Nothing happens upon joining

You can write your topic however you want, but you need to answer these questions:

  1. 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.

  2. 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.

  3. 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)

Hi! Can you try putting your LocalScript in StarterPlayer > StarterCharacterScripts? Let me know how it goes.

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

Just tried starter character, and starter player, neither seemed to work, I’m pretty sure there isn’t anything wrong with my script…

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
2 Likes
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.