Gui not enabling when IntValue requirement is reached

:wave:Hey Developers!

Im trying to make a script where a GUI enables if you get a certain value
This value is stored in leaderstats and is datastored
Here is my script for the GUI:

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

if player.leaderstats.Wins.Value >= 10 then
	Screen.Enabled = true
	print("Enabled!")
else
    print("Nothing")
end

When I play test the game “Nothing” is returned in the console

Use a loop to check every 1 or so seconds. Such as:

local Screen = game.Players.LocalPlayer.PlayerGui:WaitForChild("ScreenGui")
local player = game.Players.LocalPlayer
spawn(function()
	while task.wait(1) do 
		if player.leaderstats.Wins.Value >= 10 then
			Screen.Enabled = true
			print("Enabled!")
		else
			print("Nothing")
		end
	end
end)

Also, make the frames inside the screengui visible if you aren’t. You can use

for _, gui in pairs(Screen:GetChildren()) do
if gui:IsA("Frame") or gui.ClassName:match('Text') then
gui.Visible = true;
-- any text label, box, button or frame will be visible.
end
end
3 Likes

It’s better to listen whenever the Wins value changes rather than using a loop and spawning a new thread

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

local wins = player.leaderstats.Wins
wins:GetPropertyChangedSignal("Value"):Connect(function()
	if wins.Value >= 10 then
		Screen.Enabled = true
		print("Enabled!")
	else
		print("Nothing")
	end
end)
2 Likes

Actually true. I don’t use values ever, so I don’t really know all the functions with them. I store all my data in modules.

1 Like

should i put the script inside of the screengui, frame or in serverscriptservice?

Either the ScreenGui or Frame, the script won’t work at all in ServerScriptService

1 Like

Inside the controller of the whole system. Inside the GUI wouldn’t work as the GUI isn’t enabled. You could enable it by default, and just make the frame visible instead, and store the script inside of it.

1 Like

Yup it works thank you both for your help!
:heart:

1 Like

Awesome! Have a good day, and have fun coding!

1 Like

Better yet, use the object’s ‘Changed’ event/signal instead.

Wins.Changed:Connect(function(Value) --Value here represents the new value of the 'Wins' object.
	if Value > 9 then
		--Do code.
	else
		--Do other code.
	end
end)
1 Like