You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
When a player joins my game, I want it to check to see if they are above a certain rank in my group, then I want it to set whether the GUI is enabled or disabled based on the player’s rank.
What is the issue? Include screenshots / videos if possible!
My code is a local script, in replicated first. And it isn’t working when I join my game.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I’ve looked for and tried multiple solutions, such as changing it from the GUI to the frame, etc but nothing wants to work.
local players = game:GetService("Players")
players.PlayerAdded:Connect(function(newPlayer)
local playergui = newPlayer.PlayerGui
local rank = newPlayer:GetRankInGroup(14289900)
if rank > 250 then
playergui.AdminGui.Enabled = true
else
playergui.AdminGui.Enabled = false
end
end)
Sometimes I get an issue where the playeradded function doesnt run because It doesnt get connected until AFTER the player joins. Maybe you can move it on the top of the script or something? I usually do too much before the playeradded is connected.
If thats not the problem make sure its running by adding prints or the debugger
I would recommend using the Localplayer to do this. For example,
local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
local playergui = localPlayer.PlayerGui
local rank = localPlayer:GetRankInGroup(14289900)
if rank > 250 then
playergui.AdminGui.Enabled = true
else
playergui.AdminGui.Enabled = false
end
local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
local gui = script.Parent
local groupId = 14289900
local rankRequired = 250
local success, result = pcall(function()
return localPlayer:GetRankInGroup(groupId)
end)
if success then
if result then
if result > rankRequired then
gui.Enabled = true
else
gui.Enabled = false
end
end
end
This should just be a local script placed inside the ScreenGui itself, there’s no need to index the player instance for their “PlayerGui” folder. Additionally, GetRankInGroup() is an API-based instance method and as such it should be appropriately wrapped inside a call to pcall() as to handle any potential errors.