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

Assigning A Spawn To every Player?

So I'm making a map script, and for all the players, when they enter a map, the each get assigned their own spawn so they don't all stack on one another. Just a simple script as my attempt; tho it didn't get very far :/

wait(5)
Plyr = game.Players:GetChildren() -- All Players
Spawns = game.Workspace.TreeMap.Spawns:GetChildren() -- All Spawns

for i = 1,#Plyr do
	for x = 1, #Spawns do
		Plyr[i].Character.Torso.Position = Spawns[x].Position -- Assign Here? each torso gets its own position allocated in the for loop? right?
	end
end

I don't know and I think I have confused myself haha, Any Help much appreciated Thx, ~ Bubs

2 comments

0

what does you script currently do/

0

kills the player, no errors

2 answers

✓ Accepted answer

First, to teleport a player without killing them you need to change the Torso's CFrame, not the position. Also, with your current script, each player is just going to get teleported to EACH spawn point once (because the loops will happen for EACH player).

What this does is it places a player incrementally, placing the players at a new spawn and then just cycling back through the spawns if each spawn gets a player.

wait(5)
Plyr = game.Players:GetChildren() -- All Players
Spawns = game.Workspace.TreeMap.Spawns:GetChildren() -- All Spawns
numSpawn = 1

for i = 1,#Plyr do
	if numSpawn == #Spawns then
		Plyr[i].Character.Torso.CFrame = CFrame.new(Spawns[numSpawn].Position)
		numSpawn = 1
	
	else
		Plyr[i].Character.Torso.CFrame = CFrame.new(Spawns[numSpawn].Position)	 
		numSpawn = numSpawn + 1
		
	end
end

Updated, let me know if this works for you!

3 comments

0

Line 12 - attemp to index field '?' a nil value. im guessing its the [newSpawn] bit ?

0

Edited this, let me know what happens now

0

Ay it works! Thank you very much man!

an easier way out is you could have messed with teams, and make spawn locations and set which team is supposed to spawn to which spawn location by changing the team color properties, please upvote because im trying to be able to chat again :)

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