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)
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.
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.
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.