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

Hello! How do you make randomized spawns for players?

local Spawn1 = game.Workspace.Spawn1
local Spawn2 = game.Workspace.Spawn2
local Spawn3 = game.Workspace.Spawn3

local plr = game.Players.LocalPlayer

repeat wait() until plr.Character
script.Parent.MouseButton1Click:Connect(function()
	
local spawner = math.random(1,3)
	if spawner ==1 then
	if spawner ==2 then
	if spawner ==3 then
end)

I made three different parts and tried to make a random spawn but didn't work. Feedback would be amazing!

4 answers

Actually, no coding is necessary as ROBLOX has this feature built-in.

All you need to do is have multiple SpawnLocations in workspace. When the player spawns (as long as all spawns are enabled) it randomizes which to spawn the player at.

Hope this helped you!

2 comments

0

It kind of is needed though because if he's making a mini-game, I think the easiest thing to do is to teleport people to "spawns"

0

That's true. It really depends on what kind of game he's making

My spawns are in a folder in workspace. This makes it so I can add an infinite amount of spawns.

local spawns = game.Workspace.Spawns:GetChildren() -- here I am putting all of my spawns in a table
local db = false
--script.Parent.Touched:connect(function() -- I used a touched event

script.Parent.MouseButton1Click:Connect(function() -- for you it will be a mousebutton1click
			if db == false then -- I just wanted a debounce to be safe.
			db = true
			for i,v in pairs(game.Players:GetPlayers()) do -- looping through all of the players currently in the game.
			local RNG = math.random(1, #spawns) -- randomly generating a number from 1 to how many spawns I have. I had 3 spawns so I could have done (1,3) but I like things dependent of variables
			v.Character:MoveTo(spawns[RNG].Position) -- Here I am accessing the player from the variable V from the foor loop, and moving them to the randomly selected spawn position.
			db = false
		end
	end
end)


It is enough to create several spawn points, and players will randomly appear on them.

Iterate through every player inside of a table and make enough parts not spawn locations for the players. You can set the CFrame of the root part to the random spawns.

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