i have like 6 spawn locations but when i tried i spawned at the same one everytime, how do i make it at random?
how do i randomize spawn points?
1 answer
I don't think that there is a way to choose what SpawnLocation you spawn at without making your own parts and script. For instance, if I were to want randomized spawns I would add regular Parts into the workspace and make sure they are anchored with CanCollide set to false and a transparency of 0. I would put all of those parts in a folder named "Spawns" and place them where I want to spawn the player. The script would look as follows.
local spawns = workspace:WaitForChild("Spawns"):GetChildren() --making a table
local function spawnPlayer(hrp, spawnPoint)
wait()
hrp.CFrame = spawnPoint.CFrame + Vector3.new(0,3,0)
end
game.Players.PlayerAdded:Connect(function(plr) -- every time a player joins this will run
plr.CharacterAdded:Connect(function(char) -- every time the player spawns in this will run
local chosenSpawn = math.random(1, #spawns) -- #spawns is equal to the number of values stored in the table we created on the first line (in your case, 6)
spawnPlayer(char.HumanoidRootPart, spawns[chosenSpawn])
end)
end)
This works in my studio when I test it, let me know if anything goes wrong for you or if you have any questions. Hope I helped!
7 comments
what does it mean when it says choose a nukber between 1 and the number of spawns, i have 6 so what would i put in the spot?
The way that this script works is that when you set spawns to workspace.Spawns:GetChildren() you are making a table that contains all of the spawns. Saying #spawns gets the amount of spawns for you
That script will work fine as long as it isn't a LocalScript. I put my script in ServerScriptService.
o ok i think i get it, i put them all in the folder like you said, so saying #spawns will do all the spawns in the folder?
Yes, #spawns will be a number value that represents how many objects you have in the spawns folder (sorry if I'm a bit confusing)
ok its fine it makes total sense, thank you!
No problem.
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
I don't know if you get notified when I comment under my own post, but I have replied to you under my answer.
Also, if my answer did end up working, it would be appreciated if you could accept it. Thanks!