Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do i make a GUI only visible to People With a certain Rank?

I have an admin console that spawns maps and shows available commands. I want it to only show to people with certain ranks (RANKS: 16,17,252,253,255)

Here is my current code that doesn't work.

local rank = 16 local groupID = 4126160

script.Parent.Touched:connect(function(hit) if (hit and hit.Parent and game.Players:FindFirstChild(hit.Parent.Name)) then if (game.Players[hit.Parent.Name]:IsInGroup(groupID) and game.Players[hit.Parent.Name]:GetRankInGroup(groupID) <= rank) then script.Parent.Enabled = true else script.Parent.Enabled = false end end end)

Thanks for your help!

1 comment

0

Please edit the question and put it under lua.

1 answer

✓ Accepted answer

Your method of disabling the GUI is not at all adequate as the client could easily enable the GUI or avoid touching the brick. You also gave multiple errors in your code such as flipping your sign and not spacing properly.

Instead of doing what you did, I will create a table for all the ranks that are allowed to get the GUI, and only insert the GUI into those who are the proper rank.

In order for this to work you must NOT place the Gui in StarterGui, you must place it inside of this script. This script should be placed inside of ServerScriptService.

Ranks = {16,17,252,253,255} -- Allowed ranks
GroupID = 4126160

GUI = script:FindFirstChildOfClass("ScreenGui")

Players = game:GetService("Players")

Players.PlayerAdded:connect(function(Player)
	if Player:IsInGroup(GroupID) then
		local Allowed = false
		for _,Rank in pairs(Ranks) do
			if Player:GetRankInGroup(GroupID) == Rank then
				Allowed = true
				break -- Stop searching
			end
		end
		if Allowed then -- If  allowed to see the gui
			local NewGui = GUI:Clone() -- copy of the GUI
			NewGui.Parent = Player.PlayerGui
		end
	end
end

I hope I helped! Let me know if you have any questions.

8 comments

0

too many comments, makes it harder to read.

0

You're a real douche, m8

0

Readability is important, and there are too many comments in the code. Readability of the code can be improved by either removing them or shortening the comments

0

You should have originally kept this in a Touched event as that is what OP does. This question also needs to tell the client that the gui needs to be switched on and off. Something the server loses after cloning the gui.

0

What are you talking about? The comments are fine... I don't have any trouble reading the code

0

because the comments were shortened or removed

0

If you had a problem with the comments you could have opened the raw text

0

The comments are never a problem. If the comments are the problem, you are the problem.

This discussion is preserved as it was. New answers, comments, and votes are closed.