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

Why won't this script teleport the player to all other players?

Asked by 4 years ago

I'm trying to make my script teleport the user to all players via a while true do loop, but unfortunately it does nothing except output attempt to get length of local 'v' (a userdata value)

local lp = game.Players.LocalPlayer

wait(3)

for _,v in pairs(game.Players:GetChildren()) do
    if game:GetService("Players")[v.Name] and game:GetService("Players")[v.Name].Character then
        while true do
            local randomplayer = math.random(1,#v)
            lp.Character.HumanoidRootPart.CFrame = game:GetService("Players")[v.Name].Character.HumanoidRootPart.CFrame
            wait(1)
        end
    end
end

What did I do wrong?

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

Try this, tell me the outcome.

local lp = game.Players.LocalPlayer

wait(3)

while true do
    for _,v in pairs(game.Players:GetChildren()) do
        local randomplayer = math.random(1, #v)
        lp.Character.HumanoidRootPart.CFrame = randomplayer.Character.HumanoidRootPart.CFrame + Vector3.new(2, 0, 0)
        wait(1)
    end
end
0
You probably want to use remote events. ChasingNachos 133 — 4y
0
I just edited it to make it work a little better. ChasingNachos 133 — 4y
0
Works good, thanks my man! MustangHeart 67 — 4y
0
Of course! Always happy to help! ChasingNachos 133 — 4y
Ad

Answer this question