Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Assigning A Spawn To every Player?

Asked by 7 years ago

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

0
what does you script currently do/ patrline5599 150 — 7y
0
kills the player, no errors Bubbles5610 217 — 7y

2 answers

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

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!

0
Line 12 - attemp to index field '?' a nil value. im guessing its the [newSpawn] bit ? Bubbles5610 217 — 7y
0
Edited this, let me know what happens now patrline5599 150 — 7y
0
Ay it works! Thank you very much man! Bubbles5610 217 — 7y
Ad
Log in to vote
0
Answered by 7 years ago

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 :)

Answer this question