Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by
proo34 41
5 years ago

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!

0
Please edit the question and put it under lua. danglt 185 — 5y

1 answer

Log in to vote
0
Answered by
Vmena 87
5 years ago
Edited 5 years ago

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.

0
too many comments, makes it harder to read. User#24403 69 — 5y
0
You're a real douche, m8 User#25448 0 — 5y
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 User#24403 69 — 5y
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. xPolarium 1388 — 5y
View all comments (4 more)
0
What are you talking about? The comments are fine... I don't have any trouble reading the code 8391ice 91 — 5y
0
because the comments were shortened or removed User#24403 69 — 5y
0
If you had a problem with the comments you could have opened the raw text Vmena 87 — 5y
0
The comments are never a problem. If the comments are the problem, you are the problem. fredfishy 833 — 5y
Ad

Answer this question