Group/Rank Whitelist

player = game:GetService(“Players”)

script.Parent.ClickDetector.MouseClick:Connect(function()
if player:GetRankInGroup(5324332) <= 100 then
script.Parent.Parent.Motors.M1.DesiredAngle = math.rad(70)
script.Parent.Parent.Motors.M2.DesiredAngle = math.rad(70)
end
end)

So i’ve tried to do a door that only opens if the player has the rank 100 or over it in the group, but somehow it isn’t working so i’d like to ask you guys to help coz i’m confused.

1 Like

Your code is currently checking if the rank is less than or equal to 100. Change <= to >=.
Also you are using the service Players, you want to use game:GetService("Players).Player.

You should use:

game.Players.PlayerAdded:Connect(function(player)
--Your Code
end)

EDIT: Didn’t see the click detector.

1 Like

???

The event MouseClick passes the player who clicked as the first arg. To fix your code you only need to use that player arg passed and remove the get service at the top of your code.

2 Likes

game.Players.PlayerAdded:Connect(function(player)
script.Parent.ClickDetector.MouseClick:Connect(function()
if player:GetRankInGroup(5324332) >= 100 then
script.Parent.Parent.Motors.M1.DesiredAngle = math.rad(70)
script.Parent.Parent.Motors.M2.DesiredAngle = math.rad(70)
end
end)

So that should work right?

You don’t need to use PlayerAdded for a door that’s controlled by a ClickDetector.

local groupID = 5324332
local rankNeeded = 100
script.Parent.ClickDetector.MouseClick:Connect(function(player)
	if (player:GetRankInGroup(groupID) >= rankNeeded) then
		script.Parent.Parent.Motors.M1.DesiredAngle = math.rad(70)
		script.Parent.Parent.Motors.M2.DesiredAngle = math.rad(70)
	end
end)

tysm (sorry for all the trouble)

Yes, that should work in theory, but there is a lot of “interesting” things you are doing there.

For starters, the player will automatically be tracked by the MouseClick event on a ClickDetector, so you don’t need to include any other methods of tracking a player (like you have with the PlayerAdded event).

script.Parent.ClickDetector.MouseClick:Connect(function(player)
   if player:GetRankInGroup(5324332) >= 100 then
      script.Parent.Parent.Motors.M1.DesiredAngle = math.rad(70)
      script.Parent.Parent.Motors.M2.DesiredAngle = math.rad(70)
   end
end)

Also, it might be more beneficial (at the sacrifice of aesthetics) to make the door CanCollide false locally, this way no one aside from those group members with a rank above/equal to 100 would be able to get in.