Finding Player Who Clicked

How can I find who clicked a part? I have a click detector and a function in my script but I need to see who clicked the button to change their position.

When the Click detector is clicked it passes the Player argument.

Can you give me an example of this?

function onMouseClick(Plr)

end
 
clickDetector.MouseClick:Connect(onMouseClick)

Or

ClickDetector.MouseClick:Connect(function(Player)
-- Player
end)
1 Like

You would just get it like a normal argument from the function you connected to.

More info can be found here:

https://developer.roblox.com/en-us/api-reference/event/ClickDetector/MouseClick

So what code would I need to change the players position?

Here is an example of changing the Player position (Change YourPositionPart to the Part position you’d like)


ClickDetector.MouseClick:Connect(function(Player)
if Player.Character then
Player.Character:WaitForChild("HumanoidRootPart").Position = YourPositionPart.Position
end
end)
1 Like