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

How do I fix my script so it only teleports the player that clicks it?

It teleports everyone in the server and i want it to teleport only the player that clicks the button, i put it in a Script, i dont know what the problem is. Thank you!

function onClicked()

local p = game.Players:GetChildren()

for i = 1, #p do

	p[i].Character:MoveTo(Vector3.new(510.478, 239.667, -1800.467))

end

end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

2 comments

0

No, no, no, no, NO!!

0

My gosh, you must be a beginner, you need to find the player who clicked used it.

2 answers

✓ Accepted answer
function onClicked(plr) --Finds the player that clicked
local  pos = CFrame.new(510.478, 239.667, -1800.467) --You can change these numbers to the position you want to teleport the player to.
plr.Character.HumanoidRootPart.CFrame = pos
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)--Conects the function

1 comment

0

YES!! Thank you, this worked!!!!!! Im so new to scripting sorry!!

Hello, you need to understand FILTERING ENABLED, this is VERY VERY IMPORTANT. Use localscript!! Not script!

local button = game.LocalPlayer.PlayerGui.YOURGUI

button.MouseButton1Click:Connect(function()
	game.LocalPlayer.Character.HumanoidRootPart.CFrame = CFrame.new(YOUR POSITION)
end)

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