Make GUI appear when player stage is 11

Hi ive been trying to make a GUI appear at the top of players screens when a player reaches stage 11.

The Gui wont even activate or become visible but when i managed to make that work. It would be permanently stuck on players screens.


while wait(1) do
		
	for i,v in pairs(game.Players:GetChildren()) do

		if v.leaderstats.Stage.Value == 11 then
			
			game.StarterGui.Level100.TextLabel.Visible = true
			
			game.StarterGui.Level100.TextLabel.Text = v.Name.." REACHED STAGE 100"
			
			wait()
			
			game.StarterGui.Level100.TextLabel.Visible = false
			
		end
		end

end

Heres the code im using if anyone knows how to help! Thankyou!

Try this:

while wait(1) do
		
	for i,v in pairs(game.Players:GetChildren()) do

		if v.leaderstats.Stage.Value == 11 then
			
			game.StarterGui.Level100.TextLabel.Visible = true
			
			game.StarterGui.Level100.TextLabel.Text = v.Name.." REACHED STAGE 100"
			
			wait(1)
			
			game.StarterGui.Level100.TextLabel.Visible = false
			
		end
	end
end

I used that and it appeared on the screen but only disappeared when the player next died

Oh i see the issue, is this in a server or local script?

it is in a server script not local

When handling player UI, it’s important to do that locally. So:

–In a local script:

local player = game.Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")

while wait(1) do	
	for i,v in pairs(game.Players:GetChildren()) do

		if v.leaderstats.Stage.Value == 11 then
			
			playerGui.Level100.TextLabel.Visible = true
			
			playerGui.Level100.TextLabel.Text = v.Name.." REACHED STAGE 100"
			
			wait(1)
			
			playerGui.Level100.TextLabel.Visible = false
			
		end
	end
end

You shouldn’t handle GUI on the server.

Add a LocalScript into StarterPlayerScripts, and paste this inside:

--//Services
local Players = game:GetService("Players")

--//Variables
local LocalPlayer = Players.LocalPlayer
local PlayerGui = LocalPlayer:WaitForChild("PlayerGui")
local Stage = LocalPlayer:WaitForChild("leaderstats").Stage

--//Functions
local function SetGui()
	PlayerGui.Level100.TextLabel.Text = LocalPlayer.Name .." REACHED STAGE 100"
	PlayerGui.Level100.TextLabel.Visible = true

	task.wait(1)
	PlayerGui.Level100.TextLabel.Visible = false
end

Stage.Changed:Connect(function(stageValue)
	if stageValue == 11 then
		SetGui()
	end
end)

if Stage.Value == 11 then
	task.spawn(SetGui)
end

this is terrible practice, never use a loop for this, use .changed

Oh ok, thanks for the advice. I didn’t really look much into how it was worded, but you’re right.

You shouldn’t use a loop for this, and you shouldn’t be looping over other players too.

Just connect a changed event for the local player’s stage value.

i’d want it to show up on all players screens?

Do you want every player to see that a certain player reached stage 11?

yes thats how i’d want it to be

Okay change your server script to this then:

--//Services
local Players = game:GetService("Players")

--//Functions
local function DisplayUI(playerName)
	for i, player in ipairs(Players:GetPlayers()) do
		task.spawn(function()
			local PlayerGui = player:WaitForChild("PlayerGui")
			PlayerGui.Level100.TextLabel.Text = playerName .." REACHED STAGE 100"
			PlayerGui.Level100.TextLabel.Visible = true

			task.wait(3)
			PlayerGui.Level100.TextLabel.Visible = false
		end)
	end
end

Players.PlayerAdded:Connect(function(player)
	local Stage = player:WaitForChild("leaderstats"):WaitForChild("Stage")
	
	Stage.Changed:Connect(function(stageValue)
		if stageValue == 11 then
			DisplayUI(player.Name)
		end
	end)
end)
1 Like

okay that worked thankyou so much!!

1 Like

No problem. If you have any more questions, feel free to ask.

1 Like