GUI System updating currency display

Can anyone help fix my script I’m trying to make it so when a players currency amount changes a UI will show up on their screen. But I cant quite figure it out

My code is down below:

local player = game.Players.LocalPlayer

player:WaitForChild("leaderstats").Currency.Changed:Connect(function()
	if player.leaderstats.Currency.Value.Changed then
		
		script.Parent.LevelUp.Visible = true
		wait(5)
		script.Parent.LevelUp.Visible = false
	end
end
3 Likes

You don’t need the “if player.leaderstats.Currency.Value.Changed”, that will probably just cause an error. Instead just do this:

local player = game.Players.LocalPlayer

player:WaitForChild("leaderstats").Currency.Changed:Connect(function()
		script.Parent.LevelUp.Visible = true
		wait(5)
		script.Parent.LevelUp.Visible = false
end
2 Likes

You don’t need this if statement, and if the GUIs are being targetted by the code in the Changed Function, it should work correctly.

Actually, it won’t really change. Changed is an RBXScriptSignal object, and the if conditional checks to see if something is not false or nil, so it should work.

Doesnt seem to work still Im not sure

Wanna try adding prints to see if it even runs the function?

No im changing the values and it still does not work using the function

Did you add prints to see is the function runs?

local player = game.Players.LocalPlayer

player:WaitForChild("leaderstats").Currency.Changed:Connect(function()
                print("running")
		script.Parent.LevelUp.Visible = true
		wait(5)
		script.Parent.LevelUp.Visible = false
end

Can you show your explorer where the script is located?

What do you mean by that?? im not sure what that means im new to this

Prints are where you do something like:

print("Hello World")

You can also print variables and numbers:

local food = 10
print(food) -- prints in the output tab 10

This can be useful for debugging your code because you can see where it went wrong.

Is this a local script by the way? You can only use LocalPlayer on a local script, so just wondering.

image

Oh nevermind you just answered the question. Anyways, I would add a wait for child in there.

Change “script.Parent.LevelUp” to just “script.Parent”

1 Like

Ive done that still not working tho

Can you show the part of the explorer where your leaderstats are, probably not a value instance.

Just double checking this is your current code?

local player = game.Players.LocalPlayer

player:WaitForChild("leaderstats").Currency.Changed:Connect(function()
		script.Parent.Visible = true
		wait(5)
		script.Parent.Visible = false
end

The leaderstats don’t need to be a value instance, I use folders all the time and it works fine.

EDIT: Just realized you probably mean the level thing lol.

1 Like

No they are in values it just does show up when the players amount changes