local function teleportPlayers()
local spawns = cMap.Map.spawns:GetChildren()
local players = game.Players:GetPlayers()
for i,v in pairs(players) do
for j=1, #spawns do
if spawns[j].active == true then
v.Character.HumanoidRootPart.CFrame = spawns[j].CFrame
spawns[j].active = false
end
end
end
print("Teleported")
end
All of the for loops seem to be scripted correctly so I don’t see any mistake, or maybe I missed it.
Where is the script giving you an error? With what you just sourced I don’t even know where you run the function or how. Are you running it when a player connects? Are you running it on command? Please specify because it’s hard to help with this amount of info.
First of all, I would move the print(“Teleported”) statement to inside of your for loop. Second, assure that your spawns are active to begin with. Other than that, that’s all I can see. It’s probably an error with the “Active” statement. Are there any errors in the output?
local function teleportPlayers()
local spawns = cMap.Map.spawns:GetChildren()
for i,v in pairs(game.Players:GetChildren()) do
for j=1, #spawns do
if spawns[j].Active == true then
v.Character.HumanoidRootPart.CFrame = spawns[j].CFrame
print("Teleported")
spawns[j].Active = false
end
end
end
end
local function teleportPlayers(player)
local spawns = cMap.Map.spawns:GetChildren()
player.Character.HumanoidRootPart = spawns[math.random(1,#spawns)]
print("Teleported")
end
for index, plr in pairs(game.Players:GetChildren()) do
teleportPlayers(plr)
end
local function teleportPlayers(player)
local spawns = cMap.Map.spawns:GetChildren()
player.Character.HumanoidRootPart.CFrame = spawns[math.random(1,#spawns)].CFrame
print("Teleported")
end
for index, plr in pairs(game.Players:GetChildren()) do
teleportPlayers(plr)
end