local Spawns = game.Workspace:FindFirstChild(Name).Spawns:GetChildren() -- Get (around 25 random spawns from a folder) local SpawnLoc = math.random(1,#Spawns) --choose a random spawn script.Parent.Parent.Parent.Parent.Parent.Character:MoveTo(SpawnLoc .Position)-- move player to random spawn(etc)
I know I could name each spawn with a number but that's inefficient and I could have 100s of spawns, is there any way that I could do this using math.random? Because the Name and number of spawns change each time so I cant create a table {} or name the spawns, any help? SpawnLoc is returned as a numberValue, when it needs to be an object from the "Spawns" variable ~Thx, Bubs
You can pick a index from the table to get a random spawn. Since we already have a random number, we can plug that into the index of the table to get a random spawn.
local Spawns = game.Workspace:FindFirstChild("Put Correct Name Here").Spawns:GetChildren() local SpawnLoc = Spawns[math.random(1,#Spawns)] script.Parent.Parent.Parent.Parent.Parent.Character:MoveTo(SpawnLoc .Position)
Good Luck!