Group gui not showing

Gui that enables if someone is in a group and over rank 15

Gui is just not showing up

Tried to change the variables and it’s in a local script btw.

local players = game:GetService("Players")
local GP = 5470285
local player = game.Players.LocalPlayer

players.PlayerAdded:Connect(function()
	if player:IsInGroup(GP)then
			if player:GetRankInGroup(GP) >= 15 then
				local plrGui = player:WaitForChild("PlayerGui")
				local gui = plrGui:FindFirstChild("StageChanger")
				if gui then gui.Enabled = true end
			end
		end
end)

try:

local players = game:GetService("Players")
local GP = 5470285
local player = game.Players.LocalPlayer

if player:IsInGroup(GP)then
	if player:GetRankInGroup(GP) >= 15 then
		local plrGui = player:WaitForChild("PlayerGui")
		local gui = plrGui:FindFirstChild("StageChanger")
		if gui then gui.Enabled = true end
	end
end
2 Likes

Thanks, I didn’t know that you couldn’t do players.playeradded.

That’s not true at all. PlayerAdded works in LocalScripts. The issue is that by the time the script is executed, the player has already entered the server, so PlayerAdded does not recognise the player joining. LocalScripts are executed after game.Loaded fires and PlayerAdded can fire before then.

Using PlayerAdded here is wholly unnecessary in the first place. Omitting it, as you’ve done in your code sample, is sufficient enough.

cc @YosufRParhizkar So that you don’t carry this wrong knowledge with you. PlayerAdded works in LocalScripts, you’re just running into a timing and necessity issue.

3 Likes