Help needed with Staff only GUI

Hey there!
So I’m trying to make a GUI only visible to certain group ranks using this code in a normal script:

    if game.Players.LocalPlayer:GetRankInGroup(5702291) == 255 or game.Players.LocalPlayer:GetRankInGroup(5702291) == 254 or game.Players.LocalPlayer:GetRankInGroup(5702291) == 253 or game.Players.LocalPlayer:GetRankInGroup(5702291) == 250 or game.Players.LocalPlayer:GetRankInGroup(5702291) == 249 then
		script.Parent.Staff.Enabled = true

However, I am getting this error in the ouput:

Players.EmpxrxrPhxl.PlayerGui.StaffGui.StaffHandler:1: attempt to index nil with 'GetRankInGroup’

Now I’m obviously not quite good at scripting and that’s probably a 0815 error y’all could fix in less than a minute. Thanks in advance to anyone commenting :smiley:

1 Like

Try having a variable for the local player instead of just writing that there in the if-statement.

local player = game.Players.LocalPlayer

And then you use the player variable in place of where you have game.Players.LocalPlayer right now.


It doesn’t make a difference if I use game:GetService("Players").LocalPlayer or game.Players.LocalPlayer, does it? Just tried using GetService, that doesn’t work either. Same error.


If it’s indexing nil that means the LocalPlayer doesn’t exist… This is usually the case if the script is a ServerScript, not a LocalScript. Check to see if it’s in a LocalScript. Hope I helped :slight_smile:

1 Like

Hi! As stated in the thread I am using a server-sided script to ensure the gui can not be exploited. If that code doesn’t work in such a script, then how would I do it? I’ve found this DevHub post where it says I can use GetRankInGroup in a server script too.

Just do this:
Also, I think GetRankInGroup returns nil if his not i ngroup, so try this:

local Player = game.Players.LocalPlayer

if Player:IsInGroup(5702291) then
if Player:GetRankInGroup(5702291) >= 255 then
elseif Player:GetRankInGroup(5702291) < 255 then

You can use GetRankInGroup in a serverscript, but it’s referencing it to “LocalPlayer” which doesn’t exist in the server… The “LocalPlayer” is the client, and therefore can only be used in local scripts (client scripts)

You can try this instead if you don’t want it to be “exploited”;

local GUI = script.GUIName

game.Players.PlayerAdded:Connect(function(Player) -- When a player joins the game
     if Player:GetRankInGroup(5702291) >= 249 then -- Instead of having a bunch of values, just set it to if it's equal or higher than this rank then run the code below;
		GUI:Clone().Parent = Player:WaitForChild("PlayerGui")

Instead of setting the GUI’s enable property to true (which exploiters can do) it parents the GUI to the player’s PlayerGui. Just make sure the GUI is already Enabled


The error you’re getting is because you’re trying to call GetRankInGroup on a nil value. LocalPlayer is nil to server scripts, only LocalScripts can see it. Never use a server script in a Gui.

Your option is simple, convert this to a LocalScript. You can also do this from the server but then you’d have to fundamentally change your structure so that the script is in ServerScriptService and is cloning the Gui into an authorised player’s PlayerGui rather than a simple Enabled/Destroy call.

If you ask me, not worth the effort to handle this on the server. Exploiters can still perform interfaceless actions without the Gui. Secure your server and you have no problem to worry about.


GetRankInGroup returns 0 if they are not in the group
aka the guest rank