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

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

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

✓ Accepted answer

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

4 comments

0

You probably want to use remote events.

0

I just edited it to make it work a little better.

0

Works good, thanks my man!

0

Of course! Always happy to help!

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