I am trying to modify this sliding door to be a pool cover, but I only want it so only a certain rank and above can press it…?
local groupid = 6201590
local trigger = script.Parent
local gate = script.Parent.Parent.Gate
moving = false
open = false
function onClick()
if open == false and moving == false then
moving = true
trigger.BrickColor = BrickColor.new("Bright yellow")
for i = 1, (gate.Size.Y * 10 + 1) do
wait()
gate.CFrame = gate.CFrame*CFrame.new(0, -0.1, 0)
end
moving = false
open = true
trigger.BrickColor = BrickColor.new("Bright red")
elseif open == true and moving == false then
moving = true
trigger.BrickColor = BrickColor.new("Bright yellow")
for i = 1, (gate.Size.Y * 10 + 1) do
wait()
gate.CFrame = gate.CFrame*CFrame.new(0, 0.1, 0)
end
moving = false
open = false
trigger.BrickColor = BrickColor.new("Bright green")
end
end
script.Parent.ClickDetector.MouseClick:connect(onClick)
1 Like
If you only want a specific rank and not a range, you can simply use the return of MouseClick
, which is the player who pressed the ClickDetector and then use GetRankInGroup
on that player and then check if the rank is equal to the rank of an allowed rank
Example, this will make it so only the owner of the group can use the detector
local groupid = 6201590
local trigger = script.Parent
local gate = script.Parent.Parent.Gate
moving = false
open = false
local allowedRank = 255 --Your rank number here from 0-255
function onClick(plr)
local rank = plr:GetRankInGroup(groupid)
if rank < allowedRank then
return
end
if open == false and moving == false then
moving = true
trigger.BrickColor = BrickColor.new("Bright yellow")
for i = 1, (gate.Size.Y * 10 + 1) do
wait()
gate.CFrame = gate.CFrame*CFrame.new(0, -0.1, 0)
end
moving = false
open = true
trigger.BrickColor = BrickColor.new("Bright red")
elseif open == true and moving == false then
moving = true
trigger.BrickColor = BrickColor.new("Bright yellow")
for i = 1, (gate.Size.Y * 10 + 1) do
wait()
gate.CFrame = gate.CFrame*CFrame.new(0, 0.1, 0)
end
moving = false
open = false
trigger.BrickColor = BrickColor.new("Bright green")
end
end
script.Parent.ClickDetector.MouseClick:connect(onClick)
4 Likes
Well yes, but I am wanting it so everyone above that rank (Including the rank) can click it.
That’ll do as you want, simply just change allowedRank
to the rank you want. you can check your group’s ranks to see the number they have. What my code does is if your rank is less than the rank that is allowed to use it, it stops the code there until it is clicked again and checks again
What I am saying is that if like a player is less than a rank then it will return then end, but if they are in that rank or above it it would work.
That’s what the code is doing
local rank = plr:GetRankInGroup(groupid)
if rank < allowedRank then
return
end
Does what you just said. Gets the rank, is the rank less than the rank that is allowed to use the detector? if yes, return, other wise (meaning their rank is equal or greater), do something
Yes, I understand now. Thank you!
1 Like