Gui Issue/Leaderstats Issue

Hello developers!

I’m running into an issue with my Gui.
It is supposed to become visible when a certain requirement is reached on your leaderstats.
While it is working 100% of the time in Roblox studio, it barely works while playing in the actual client. Here is the script I wrote for it:

local unlock2 = script.Parent.Parent.Lv5
local Level = game.Players.LocalPlayer.leaderstats.Level

Level.Changed:Connect(function(Value)
	if Level.Value >= 4 then
		script.Parent.Visible = false
		unlock2.Visible = true
		print("Unlocked")
	else
		print("Locked")
	end
end)

A solution I originally tried was to put a wait command at the top of the script but that didn’t seem to have any effect

1 Like

Personally, I use GetPropertyChangedSignal, it fires only when the property given is changed. I’m not sure if it’ll make a difference, however, you could try

Level:GetPropertyChangedSignal('Value'):Connect(function()
	if Level.Value >= 4 then
		script.Parent.Visible = false
		unlock2.Visible = true
		print("Unlocked")
	else print("Locked") end
end)

The code looks fine, I think the issue might be external to this script.

For instances such as IntValues and NumberValues, the .Changed event only fires when the .Value property is changed.

local unlock2 = script.Parent.Parent.Lv5
local Level = game.Players.LocalPlayer.leaderstats.Level

You may need to wait for these instances to load/replicate on the server in a live session.

Tried it out and nothing seems to have changed. Really confused on why this is happening. There is no real pattern to when it becomes visible and when it doesn’t so it’s really frustrating :confused:

There isn’t necessarily anything external. All this script does is make an textbutton visible. No other script counteracts it.

The annoying this with this issue is that its working consistently in studio all the time. Never once has it not become visible. Herer are two pictures. The first one is shown in studio. It works every single time. The second one is shown in the actual client.

That’s your code, I was just indicating where changes need to be made.

https://developer.roblox.com/en-us/api-reference/function/Instance/WaitForChild

1 Like

The code waiting for the value won’t really matter because I know that it works. There is something with the actual Roblox client that is different from Roblox studio that prevents those Guis from becoming enabled.