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

How do I get the person who clicked a button from a ClickDetector? [Solved]

Asked by 9 years ago

If you have a button with a CLickDetector, and you only want rank+ or team only, or something to use it, how do I find the player from the click to check if the person is rank+, team, etc?

I know I need something like this...

script.Parent.ClickDetector.MouseClick:connect(function()
    --*something to find the player*
    if Player.TeamColor == BrickColor.new("Really red") then
        script.Parent:Remove()
    end
end)

2 answers

Log in to vote
1
Answered by
Xetrax 85
9 years ago

All you need to edit is :

script.Parent.ClickDetector.MouseClick:connect(function(Player) --The Player is already there the MouseClick function actually gets the player, you just needed to add in the parameter for them.
    --You don't need anything to find the player, but verifying them would be good.
    if game.Players:FindFirstChild(Player.Name) then
        if Player.TeamColor == BrickColor.new("Really red") then
            script.Parent.remove()
        end
    end
end)

Hope that helped.

0
Well. I tried something like that before, and I did print(Player) and it gave me a number. TypicalModerator 110 — 9y
0
What kind of script is this in? Also, you should try: print(Player.Name) Xetrax 85 — 9y
0
It was a while ago, so I might of done .Name, but I don't know. Thanks for the help though! And it's in a ServerScript. TypicalModerator 110 — 9y
1
Verifying the player would be excessive. It's best to just add the "Player" argument and leave it at that. Redbullusa 1580 — 9y
View all comments (5 more)
0
I'm sure just printing (Player) prints the ID of the Player Object relative to your game, I might be wrong, and no problem. Xetrax 85 — 9y
0
@Redbullusa, Its not that excessive, its just adding one if statement, and barely a second more of processing power. Xetrax 85 — 9y
0
Well, thanks though for the help! TypicalModerator 110 — 9y
0
No need to check for the Player to exist. Also, printing objects works fine normally. Perci1 4988 — 9y
0
Ah, I was thinking it worked like Java, where if you just do print(Object) it printed the specific Object's ID. Xetrax 85 — 9y
Ad
Log in to vote
1
Answered by 9 years ago

I don't understand what you mean by "find," so this is the closest I can think of.

script.Parent.ClickDetector.MouseClick:connect(function(Player)
    if Player:GetRankInGroup(GROUPID) >= RANKNUMBER and Player.TeamColor == BrickColor.new("Really red") then
        print(Player.Name.. "clicked the button")
        script.Parent:Remove()
    end
end)

Answer this question