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

How do I find the player who clicked?

Asked by 8 years ago

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)

0
Can you add more info, what type of button are you useing? User#5423 17 — 8y
0
Clickdetector iSidersz 70 — 8y
0
Just wanted to add that a click detector will not work with filtering enabled. User#5423 17 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

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)
0
How do I find the player? like what do I do to find the player in the workspace iSidersz 70 — 8y
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. bob10110 20 — 8y
Ad

Answer this question