I've seen a lot of people do round based games and use math.random() to choose what spawn the player goes to. I've been running into a lot of trouble with this. Whenever I use it it tells me that whatever number it came up with is not a valid object in spawns.
Script:
local Spawns = workspace.MapStorage.Map:GetChildren()
local chosenmap = math.random(1,#Spawns)
for i, v in pairs(game.Players:GetPlayers()) do
local name = v.Name
if workspace:FindFirstChild(name) then
workspace[name].Torso.CFrame = CFrame.new(workspace.MapStorage.Map[chosenmap].Position)
end
end
I also have a script that changes the spawns parent so it can't be used again until the end of the round where the main script puts it back.

1 comment
thanks