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

How come this teleportation does not work?

play = game.Players:GetChildren() 
for i = 1,#play do 
if p[i] ~= nil then
if play[i].TeamColor == game.Teams.Runners.TeamColor then 
char = play[i].Character
if char ~= nil then 
torso = char:findFirstChild("Torso") 
if torso ~= nil then 
torso.CFrame = game.Workspace.RunnerSpawn.CFrame + Vector3.new(math.random(-6, 6), 0, 		math.random(-6, 6))
wait(0.025)
end 
end 

When this script is fired and their are more than 2 people on the Runners team, only 1 one of them are teleported. I am trying to figure out why it won't teleport more than 1 people to the Spawn. Can anyone help me?

6 comments

0

What is p[i]? You don't have it defined anywhere.

0

p[i] is shortcut for "play[i]"

0

Even if I added play[i], the people still won't teleport to the RunnerSpawn.

0

You can't do p[i] unless you define p somewhere. Since you only defined play, p is nil. You problem also could be that the script runs as soon as the game starts, so therefore some players might not be loaded yet.

0

After everyone loads in and the 2nd time comes around, it still won't teleport all the players, even if I put play[i].

0

Oh I see the problem now. It was hard to tell with it not tabbed correctly, but you don't have nearly enough ends. You have 2, you need 5.

1 answer

✓ Accepted answer

I believe your problem is that you are missing several ends. Here is your code with the correct amount:

play = game.Players:GetChildren() 
for i = 1,#play do 
if play[i] ~= nil then
if play[i].TeamColor == game.Teams.Runners.TeamColor then 
char = play[i].Character
if char ~= nil then 
torso = char:findFirstChild("Torso") 
if torso ~= nil then 
torso.CFrame = game.Workspace.RunnerSpawn.CFrame + Vector3.new(math.random(-6, 6), 0,       math.random(-6, 6))
wait(0.025)
end 
end 
end
end
end

Also, p[i] has not been defined. I have changed it to play[i] so it would work.

3 comments

0

Wow steal my answer much?

0

Thank you, SlickPwner! I guess I kept messing with the "ends". Like, sometimes I put too little "ends" sometimes too many. But thank you.

0

I did not even notice you answered, Perci.. I'm sorry if my answer was similar to yours, but I just wrote what I saw.

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