Rank Lock on Alarm System

So I have a Control Room with multiple alarms and I wondering how to rank lock the buttons so only Executives can use the alarms.

OnButton Script

function onClicked()

	workspace.Alarms.CodeBlack:Play()
	for i, Part in pairs(workspace.Lights:GetChildren()) do
		if Part.Name == "Part" then
			Part.Color = Color3.fromRGB(0, 0, 0)
			Part.SurfaceLight.Color = Color3.fromRGB(0, 0, 0)
		end
	end
end


script.Parent.ClickDetector.MouseClick:connect(onClicked)
1 Like

Please search before posting. Use this in an if statement encapsulating the code currently in onClicked.

1 Like
function onClicked(Player)
    if Player:GetRankInGroup(groupId) < 250 then return end
    -- script will only get here if the player's rank is greater than or equal to 250
1 Like

So something like

function onClicked(Player)
    if Player:GetRankInGroup(groupId) < 250 then return

workspace.Alarms.CodeBlack:Play()
	for i, Part in pairs(workspace.Lights:GetChildren()) do
		if Part.Name == "Part" then
			Part.Color = Color3.fromRGB(0, 0, 0)
			Part.SurfaceLight.Color = Color3.fromRGB(0, 0, 0)
		end
	end
end


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

Or do I need to add the end?

Add an end after return, idk why you deleted it

function onClicked(Player)
	if Player:GetRankInGroup(groupId) < 250 then return end -- if rank < 250 then stop function and close out the if statement
	workspace.Alarms.CodeBlack:Play()
	for i, Part in pairs(workspace.Lights:GetChildren()) do
		if Part.Name == "Part" then
			Part.Color = Color3.fromRGB(0, 0, 0)
			Part.SurfaceLight.Color = Color3.fromRGB(0, 0, 0)
		end
	end
end


script.Parent.ClickDetector.MouseClick:connect(onClicked)
function onClicked(Player)
    if Player:GetRankInGroup(groupId) < 250 then return end

workspace.Alarms.CodeBlack:Play()
	for i, Part in pairs(workspace.Lights:GetChildren()) do
		if Part.Name == "Part" then
			Part.Color = Color3.fromRGB(0, 0, 0)
			Part.SurfaceLight.Color = Color3.fromRGB(0, 0, 0)
		end
	end
end


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

I tested it and it worked, thanks bro [Also if I wanted to add another group would I do something like…

if Player:GetRankInGroup(groupId) < 250 or if Player:GetRankInGroup(gruopID) < 233 then return end

You probably know this, but each rank has a number.

Example: The bottom number is the rank number. That number is what the script will get.

So, if I wanted to get Moderator then I would put:

if Player:GetRankInGroup(groupId) == 2 then
    print("Moderator")
end

Else if I wanted to get Moderator or above then I would do:

if Player:GetRankInGroup(groupId) <= 2 then
    print("Moderator or above")
end
local Groups = {
	[12345678] = 250,
	[90852323] = 233
}

function onClicked(Player)
	local Authorized = false
	for ID, MinimumRank in pairs(Groups) do
		if Player:GetRankInGroup(ID) >= MinimumRank then
			Authorized = true
			break
		end
	end
	
	if Authorized then
		workspace.Alarms.CodeBlack:Play()
		for i, Part in pairs(workspace.Lights:GetChildren()) do
			if Part.Name == "Part" then
				Part.Color = Color3.fromRGB(0, 0, 0)
				Part.SurfaceLight.Color = Color3.fromRGB(0, 0, 0)
			end
		end
	end
end


script.Parent.ClickDetector.MouseClick:connect(onClicked)
3 Likes

Thanks dude, you have been a big teacher/helper with my alarm system, I really appreciate it!