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

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

Asked by
c4ots 12
3 years ago
Edited 3 years ago

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)

0
No, no, no, no, NO!! epoke466 100 — 3y
0
My gosh, you must be a beginner, you need to find the player who clicked used it. hoth7 45 — 3y

2 answers

Log in to vote
0
Answered by
epoke466 100
3 years ago
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
0
YES!! Thank you, this worked!!!!!! Im so new to scripting sorry!! c4ots 12 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

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)

Answer this question