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 prevent people from spawning at the same spawn?

In my minimap's there are 25 spawns. My problem is that there's a 1 in 25 chance of someone being spawned in the same place, and I'm trying to prevent this. How do I prevent no two people from spawning at the same spawn? Thank you!

function MovePlayers()
	local Players = game.Players:GetPlayers()
	local Spawnso = game.Workspace.Map.Spawns:GetChildren()
	for i, v in pairs(Players) do
		local ToSpawn = math.random(1, #Spawnso)
		if v.GameBool.Value == true then
		v.Character.HumanoidRootPart.CFrame = Spawnso[ToSpawn].CFrame * CFrame.new(0,5,0)
		v.Ingame.Value = true
		-- the last part is probably not needed but oh well
		wait(0.05)
		v.Character.Torso.Anchored = true
		end
	end
end

1 answer

You could make a table; once you spawn a player at a part, place that part inside the table, or move it to a different directory. You can check if that part is allready in the table, if it is, don't spawn the player there and retry. I personally would prefer moving the part to a different parent.

3 comments

0

How do I place it inside a table?

0

table.insert(TABLE table, ANY, NUMBER Position)

0

How do i make an if statement or function of when a player spawns at a point?

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