Whenever I try to run the script, the output just says "ServerScriptService.Script:14: attempt to index field '?' (a nil value)" I don't know what's happening, because if I remove the CFrame, the output just says "expecting CFrame". Help?
local MapsLocation = ServerStorage:WaitForChild("Maps") local plrs = {} local GetMaps = MapsLocation:GetChildren() local MapToAppear = GetMaps[math.random(1, #AVMaps)] local MapCloned = MapToAppear:Clone() MapCloned.Parent = game.Workspace local SpawnBricks = MapCloned:FindFirstChild("Spawn") local SpawnsToTeleport = SpawnBricks:GetChildren() wait(3) for i, plr in pairs(plrs) do if plr then char = plr.Character if char then char:FindFirstChild("HumanoidRootPart").CFrame = SpawnsToTeleport[1].CFrame table.remove(SpawnsToTeleport, 1) end
It's because you are indexing an empty table, you have no value for the player in the table.
local plrs = {}
-- Empty table
for i, plr in pairs(plrs) do
-- indexing empty table
char:FindFirstChild("HumanoidRootPart").CFrame = SpawnsToTeleport[1].CFrame
-- indexing nil value
So, I discovered that I could use the variable SpawnsToTeleport, use it as a table and put the SpawnBricks variable in.
local MapsLocation = ServerStorage:WaitForChild("Maps") local plrs = {} local GetMaps = MapsLocation:GetChildren() local MapToAppear = GetMaps[math.random(1, #AVMaps)] local MapCloned = MapToAppear:Clone() MapCloned.Parent = game.Workspace local SpawnBricks = MapCloned:FindFirstChild("Spawn") local SpawnsToTeleport = {SpawnBricks} wait(3) for i, plr in pairs(plrs) do if plr then char = plr.Character if char then char:FindFirstChild("HumanoidRootPart").CFrame = SpawnsToTeleport[1].CFrame table.remove(SpawnsToTeleport, 1) end
It didn't give me the error again, so yay?