I have a button that opens up a door when pressed, however I want to make it so certain ranks can open it. It worked before when everyone could open/close it, but it doesn’t work anymore once I implemented the certain ranks.
Could you please specify what exactly doesn’t work? Does the doors not open at all or do they open regardless of what rank the player is? Also do you get any errors?
If you did add the print statement before the first line of your script and it doesn’t print any value, that means the value of Player:GetRankInGroup(5221697) is nil before the beginning of this script.
Your problem does not lie in this script, other than the if Player:GetRankInGroup(5221697) check, which is not really the problem. The check itself is fine, but …
Is 5221697 the correct group number? What can you do to confirm that?
Is this Player in this Group? Are you certain they have rank value in this Group? Where and when was that set?
You may need to write more basic test checks on this Player and this Group either at the beginning of the script or before the script runs, or disable this script and write another script with some tests and checks in it.
Also, to make your code more efficient you could just tag all the doors with a ‘door’ tag and use the collection service for modifying the each door’s transparency and canCollide properties, here is the info on it CollectionService | Documentation - Roblox Creator Hub
That’s not how you use a Debounce. In this case you’re relegating it to a standard boolean flag to describe the door’s state. You also have some bad code going on in the case of your if statement and running the group check per condition.
You can combine both a Debounce and a state.
local ClickDetector = nil
local OpenState = false
local Debounce = false
ClickDetector.MouseClick:Connect(function (player)
if player:GetRankInGroup(5221697) >= 17 then
if not Debounce then
Debounce = true
OpenState = not OpenState
if OpenState then
-- Open the door
else
-- Close the door
end
Debounce = false
end
end
end)
This is cleaner. Any code is prevented from continuing if the user does not have the required credentials. If they do, then it checks to see if the function is no debounced. If it isn’t, it continues on and flips the state of the door before acting on it.
I think he wants you to click to open and then click to close thats why he is using the debounce variable. I know its used to prevent excessive firing of something.