Hey, I’m trying to code a click teleport script, what I have currently teleports everyone in the server. I’m unsure how to modify it to only teleport the player who clicked it… This is my current script:
function onClicked()
local p = game.Players:GetChildren()
for i = 1, #p do
p[i].Character:MoveTo(Vector3.new(0.041, 1925.918, 9736.038))
end
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)
Put something in the parameters to know which player that clicked it.
function onClicked(player)
player.Character:MoveTo(Vector3.new(0.041, 1925.918, 9736.038))
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)
MouseClick shows that it returns a player parameter. This means we can target who clicked and teleport only their character.
function onClicked(player)
if player.Character then
player.Character:MoveTo(Vector3.new(0.041, 1925.918, 9736.038))
end
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)
Humanoid:MoveTo() makes the character walk to the position. Model:MoveTo() teleports the model to the position. As the character is a model, using Character:MoveTo() was correct.