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 find the localplayer in this script?

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

✓ Accepted answer

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

1 comment

0

thank you so much, i didn't know it was on the wiki

The event MouseClick has 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 FilteringEnabled turned on.

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

Roblox Wiki: API:Class/ClickDetector/MouseClick

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