✓ Accepted answer
- Please tab your code correctly. It will be easier to read and will look more professional.
local MapDir = game.ServerStorage.Maps
local PlayerDir = game.Players
local WaitTime = 10
local RoundTime = 600
local Started = false
function GameStart()
MapDir:GetChildren()
for i = 1, #MapDir do
local m = Instance.new('Message', workspace)
m.Text = "Map chosen: "..MapDir[i].Name.." by: "..MapDir[i].CreatedBy.Value..""
wait(WaitTime)
MapDir[i]:Clone().Parent = workspace.MapHolder
PlayerDir:GetChildren()
for i = 1,#PlayerDir do
PlayerDir[i]:LoadCharacter()
Started = true
m:remove()
end
end
end
GameStart()
- On line 8 and 14, you created a couple of tables.
MapDir:GetChildren()
PlayerDir:GetChildren()
You're on the right track, but this won't work because that's all you did. You didn't set it to a variable or anything. Line 8 will be fixed in the 3rd bullet, but line 14 is the one that needs fixing right here, because the amount of players in the server will change because of players leaving/entering.
local CurrPlayerDir = PlayerDir:GetChildren()
for i = 1, #CurrPlayerDir do
CurrPlayerDir[i]:LoadCharacter()
Started = true
m:Destroy()
end
MapDir is set to the WRONG data type. What the "for" loop on line 9-20 is intended to do is index a table. But MapDir is not a table, it's something else. On line 8, It's trying to get the length of the container of the maps, not regarding the actual THINGS in the container.
local MapDir = game.ServerStorage.Maps:GetChildren()
- OPTIONAL For convenient purposes, you can just use a generic "for" loop rather than a numeric "for" loop.
TABLE = {}
for i = 1, #TABLE do
TABLE[]
end
TABLE = {}
for i, v in pairs(TABLE) do
v
end
With the generic "for" loop, you get to type a lot less than the former, because the variable for value is a lot shorter than indexing a table (table[key]). But that depends on the purpose of the "for" loop. The generic "for" loop is good for tables.
#FONT SIZE TEST
#test
hashtag
test
hyphen under the line
test
nothing
2 comments
whats the error with if?
nevermind i think i found the error