So I want it so when a player clicks a button it changes the color of a tool in his inventory. I can do that but how do I find the player who clicked? (clickdetector)
COMMUNITY QUESTION
How do I find the player who clicked?
1 answer
A quick check of the wiki turned up this. Basically, the MouseClick event knows the player that clicked it and we can use that.
--Script is assumed to be placed inside the Part the ClickDetector resides in.
function onClicked(player)
print("Button clicked by " .. player.Name);
--Insert code to adjust the player's tool
--Edit: A demonstration of how to do stuff with the player's character, as shown by the example of adding Sparkles to the character's torso.
local torso = player.Character:findFirstChild("Torso")
if torso == nil then return end
local spark = Instance.new("Sparkles")
spark.SparkleColor = Color3.new(1, 0, 0)
spark.Parent = torso
wait(2)
spark:Destroy()
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)
2 comments
0
How do I find the player? like what do I do to find the player in the workspace
0
Right now, "player" refers to the object in the Players list. If you want their character in the Workspace, you could get the player's character model with "player.Character" -- I'll edit in a bit more code to show how you might do stuff with that.
This discussion is preserved as it was. New answers, comments, and votes are closed.

3 comments
Can you add more info, what type of button are you useing?
Clickdetector
Just wanted to add that a click detector will not work with filtering enabled.