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

How come this teleportation does not work?

Asked by
Yeevivor4 155
10 years ago
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?

0
What is p[i]? You don't have it defined anywhere. Perci1 4988 — 10y
0
p[i] is shortcut for "play[i]" Yeevivor4 155 — 10y
0
Even if I added play[i], the people still won't teleport to the RunnerSpawn. Yeevivor4 155 — 10y
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. Perci1 4988 — 10y
View all comments (2 more)
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]. Yeevivor4 155 — 10y
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. Perci1 4988 — 10y

1 answer

Log in to vote
0
Answered by 10 years ago

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.

0
Wow steal my answer much? Perci1 4988 — 10y
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. Yeevivor4 155 — 10y
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. SlickPwner 534 — 10y
Ad

Answer this question