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

How do i find the localplayer in this script?

Asked by
sad_eyez 162
8 years ago

I know you can't use localplayer in a normal script, so I need to know what other way I can find the player in this script, i'm just used to using local scripts, thank you if you can help.

script.Parent.MouseClick:connect(function() --The Parent of this is a Click Detector
    local Player = game.Players.LocalPlayer

2 answers

Log in to vote
4
Answered by
XAXA 1569 Moderation Voter
8 years ago

The MouseClick event of a ClickDetector passes the player who clicked the button (playerWhoClicked, for example) as the first argument of the callback function.

script.Parent.MouseClick:connect(function(playerWhoClicked)
    local Player = playerWhoClicked -- you don't even need this line. just use playerWhoClicked directly
    --TODO: Rest of the code
end)

For more details, please take a look at the wiki page for the MouseClick event, it also has another example: http://wiki.roblox.com/index.php?title=API:Class/ClickDetector/MouseClick

0
thank you so much, i didn't know it was on the wiki sad_eyez 162 — 8y
Ad
Log in to vote
1
Answered by
Gamenew09 180
8 years ago

The event MouseClickhas a argument that is the player who clicked, you can use the argument to determine which player clicked the ClickDetector. Note that this doesn't work with FilteringEnabledturned on.

script.Parent.MouseClick:connect(function(playerWhoClicked)
    -- Do what you need to do...
end)

Roblox Wiki: API:Class/ClickDetector/MouseClick

Answer this question