Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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.

9 comments

0

Well. I tried something like that before, and I did print(Player) and it gave me a number.

0

What kind of script is this in? Also, you should try: print(Player.Name)

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.

1

Verifying the player would be excessive. It's best to just add the "Player" argument and leave it at that.

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.

0

@Redbullusa, Its not that excessive, its just adding one if statement, and barely a second more of processing power.

0

Well, thanks though for the help!

0

No need to check for the Player to exist. Also, printing objects works fine normally.

0

Ah, I was thinking it worked like Java, where if you just do print(Object) it printed the specific Object's ID.

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)

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