How would I make/help with a script that only works if a certain group rank clicks it

I am trying to make a script that only activates if a player who is the owner of a group clicks the ClickDetector, but it just doesn’t work. I get no errors, and it’s not an issue with the main part of the script, it just won’t carry out the script.

Here it is

local GroupId = 6012187
	
function onClicked(player)
	if player.Parent and player.Parent:FindFirstChild("Humanoid") and game.Players:GetPlayerFromCharacter(player.Parent) then
		local Player = game.Players:GetPlayerFromCharacter(player.Parent)
		if Player:GetRankInGroup(GroupId) == 255 then
			--what I refer to as the 'main part of the script'
			workspace.Bright.Color = Color3.fromRGB(255, 0, 0)
			
		end
	end
end

script.Parent.Parent.ClickDetector.MouseClick:connect(onClicked)

Thank you in advance.

The player parameter is a player. Not a character. Just remove the character check and any logic interpreting it as a character, then directly compare the rank in the group.

https://developer.roblox.com/en-us/api-reference/event/ClickDetector/MouseClick

local GroupId = 6012187

function onClicked(player)
	if player:GetRankInGroup(GroupId) == 255 then
		workspace.Bright.Color = Color3.fromRGB(255, 0, 0)
	end
end

script.Parent.Parent.ClickDetector.MouseClick:connect(onClicked)
2 Likes

Oh I see, thanks, it works! :+1: I’ll try researching with more variety, rather than just searching and looking for the exact result. Thank you again :smiley: