Button Door For Groups

I am sure you have all seen those pretty simple models that when you click a button, a door opens. I was wondering how I could change this so when you click the button it only opens if you are a certain rank in a group.

Using this script how could I adapt it to only work with a certain rank ID from a certain group?

 function myfunction()
 
 script.Parent.Parent.Door.Transparency = 0.7 
 script.Parent.Parent.Door.CanCollide = false   
                                                                                       
                                                                                        
 end                            

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

There’s a lot of resources to help us do this.

First, we can find which player clicked the button because the ClickDetector.MouseClick function passes a “PlayerWhoClicked” parameter. Then, we can use Player:GetRankInGroup(id) and check if it is >= whatever rank you want.

MouseClick
GetRankInGroup

function myfunction()

if Player:GetRankInGroup(4097817) == 8 then
script.Parent.Parent.Door.Transparency = 0.7 
script.Parent.Parent.Door.CanCollide = false   
                                                                                      
                                                                                       
end                            

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

I tried this, any ideas why it did not work. Sorry I am new to scripting.

When you declare the function, you need to add the Player parameter.

function myFunction(Player)
    ...
end

Here’s some documentation on functions.

If you’re new to scripting, I would reccomend reading documentation or watching some YT tutorials.

1 Like

I have been looking for tutorials on this for a while now, no luck. Do you know any tutorials that could help?

1 Like
local door = script.Parent.Parent.Door
local group = 4097817
local requiredRank = 8

script.Parent.ClickDetector.MouseClick:connect(function(plr)
    if plr:GetRankInGroup(group) >=requiredRank then
    door.Transparency = .7
    door.CanCollide = false
end
end)

If this script doesn’t work, then I don’t know what to tell you.

1 Like

For scripting in general, Alvin_Blox has some great tutorials on his channel.

As for the door script, just go with what Deezylolz and I said.

2 Likes

Thank you so much, life saver!!