Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

how do i randomize spawn points?

i have like 6 spawn locations but when i tried i spawned at the same one everytime, how do i make it at random?

2 comments

0

I don't know if you get notified when I comment under my own post, but I have replied to you under my answer.

0

Also, if my answer did end up working, it would be appreciated if you could accept it. Thanks!

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

1

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?

0

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

0

That script will work fine as long as it isn't a LocalScript. I put my script in ServerScriptService.

0

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?

0

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)

0

ok its fine it makes total sense, thank you!

0

No problem.

This discussion is preserved as it was. New answers, comments, and votes are closed.