generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: I have an issue with my change map script

Previous Thread :: Next Thread 
xWOWZABOYx is not online. xWOWZABOYx
Joined: 05 Aug 2010
Total Posts: 2689
30 Mar 2013 08:20 AM
So here's the script:

specialPlayersOnly = true

showMessages = true

maps = {"AirP", "SIMRemove", "BasicSF"}

playerList = {"secret56310", "JasonIIII", "BrainK2355", "SONICTHEHEDGEHOGXX", "EliteHunter699", "xWOWZABOYx", "Dracorex001", "Crystalality", "Byas", "PerilousDanger", "SonicGuy25", "antony68204", "laxman15", "Rebelliousdude", "RAG3GUY", "Ffernando"}

command = "LOAD "

function printMessage(text)
if showMessages == true then
msg = Instance.new("Message", game.Workspace)
msg.Text = text
wait(3)
msg:Remove()
else end
end

function removeCurrentMap(newMap)
for i = 1, #maps do
if maps[i] ~= newMap then
if game.Workspace:findFirstChild(maps[i]) then
game.Workspace:findFirstChild(maps[i]):Remove()
printMessage(game.Workspace:findFirstChild(maps[i]).Name.." Removed")
end
end
end
end

function setNewMap(newMap)
if game.Lighting:findFirstChild(newMap) then
game.Lighting:findFirstChild(newMap):Clone().Parent = game.Workspace
printMessage(newMap.." Loaded")
else
printMessage(newMap.." NotFound")
end
end

function checkMessage(msg)
for i = 1, #maps do
if msg == command..maps[i] then
removeCurrentMap(maps[i])
wait(1)
setNewMap(maps[i])
end
end
end

game.Players.PlayerAdded:connect(function(player)
if specialPlayersOnly then
for i = 1, #playerList do
if player.Name == playerList[i] then
player.Chatted:connect(checkMessage)
end
end
else
player.Chatted:connect(checkMessage)
end
end)

Anyways, the script throws an error:
Workspace.LoadMapOnChat:25: attempt to index a nil value

Here's the stack trace:
Workspace.LoadMapOnChat, line 25 - global removeCurrentMapWorkspace.LoadMapOnChat, line 43

Let's say I load the first map, then try and load the second.

It'll load map#1 and say "map#1 Loaded" in a message. Then when I try and load the second one, it removes map#1, but then throws an error, and doesn't come up with a message or load map#2.

I'm not entirely sure what I've done wrong, help, please?

【◄[ϟ]〓☜✪ xWOWZABOYx; FCO, SQN COM, Scientist, Veteran, Visionary ✪☞〓[ϟ]►】
Report Abuse
ElectricAxel is not online. ElectricAxel
Joined: 15 May 2009
Total Posts: 16239
30 Mar 2013 10:40 AM
Uhm, you said "map[i].Name" and then tried to remove it. Your "maps" are strings, not objects, so you cannot "index" them. (Index is ... what you do to tables and objects, but a dot to access another thing thats inside it, in this case, Name)
Report Abuse
xWOWZABOYx is not online. xWOWZABOYx
Joined: 05 Aug 2010
Total Posts: 2689
30 Mar 2013 11:53 AM
So if I changed it to this:

printMessage(game.Workspace:findFirstChild(maps[i]).." Removed")

it'd work?

【◄[ϟ]〓☜✪ xWOWZABOYx; FCO, SQN COM, Scientist, Veteran, Visionary ✪☞〓[ϟ]►】
Report Abuse
xWOWZABOYx is not online. xWOWZABOYx
Joined: 05 Aug 2010
Total Posts: 2689
30 Mar 2013 12:00 PM
Nope, still throws an error. This time, trying to concentrate a nil value.

【◄[ϟ]〓☜✪ xWOWZABOYx; FCO, SQN COM, Scientist, Veteran, Visionary ✪☞〓[ϟ]►】
Report Abuse
12packkid is not online. 12packkid
Joined: 24 Jun 2011
Total Posts: 1418
30 Mar 2013 12:03 PM
Concentrating a nil value means, you're trying to edit something that does not exist. And then trying to do more stuff with it.

†† 12packkid ∞∞ LuaLearners Teacher ≠≠ Wind is light, but darker... ††
Report Abuse
xWOWZABOYx is not online. xWOWZABOYx
Joined: 05 Aug 2010
Total Posts: 2689
30 Mar 2013 12:54 PM
Well can someone tell me how to fix the script then please?

【◄[ϟ]〓☜✪ xWOWZABOYx; FCO, SQN COM, Scientist, Veteran, Visionary ✪☞〓[ϟ]►】
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image