I am making a teleporter that would teleport to a certain brick then the next person that goes to that teleporter will teleport to another brick then etc. But the problem is the loop. After every 5th teleport the teleporter only teleports to one brick and not teleport to another. Could fix the problem or explain to me why?
A = 0
while true do
wait(1)
if A == 0 then
script.Parent.Touched:connect(function(p)
if p.Parent:findFirstChild("Torso") and A == 0 then
A = A + 1
p.Parent.Torso.CFrame = script.Parent.Parent["1"].CFrame + Vector3.new(0,5,0)
while true do
wait(1)
if A == 1 then
script.Parent.Touched:connect(function(p)
if p.Parent:findFirstChild("Torso") and A == 1 then
A = A + 1
p.Parent.Torso.CFrame = script.Parent.Parent["2"].CFrame + Vector3.new(0,5,0)
while true do
wait(1)
if A == 2 then
script.Parent.Touched:connect(function(p)
if p.Parent:findFirstChild("Torso") and A == 2 then
A = A + 1
p.Parent.Torso.CFrame = script.Parent.Parent["3"].CFrame + Vector3.new(0,5,0)
while true do
wait(1)
if A == 3 then
script.Parent.Touched:connect(function(p)
if p.Parent:findFirstChild("Torso") and A == 3 then
A = A + 1
p.Parent.Torso.CFrame = script.Parent.Parent["4"].CFrame + Vector3.new(0,5,0)
while true do
wait(1)
if A == 4 then
script.Parent.Touched:connect(function(p)
if p.Parent:findFirstChild("Torso") and A == 4 then
A = A + 1
p.Parent.Torso.CFrame = script.Parent.Parent["5"].CFrame + Vector3.new(0,5,0)
while true do
wait(1)
A = 0
end
end
end)
end
end
end
end)
end
end
end
end)
end
end
end
end)
end
end
end
end)
end
end

2 comments
I'm not sure on the specifics with Lua, but shouldn't A be a string if he's indexing objects called 1, 2, and 3 etc... - they aren't necessarily stored under the numerical keys.
Yeah, I updated that 12 seconds before you posted your comment.