I cant make my GUI visible with Player IntValue

I am trying to make one player GUI visible with IntValues like, if my IntValue >= 1 then this GUI will be visible for me. I can´t find out what it is , maybe this script can´t find my IntValue.

local player = game.Players.LocalPlayer 
local leaderstats = player:WaitForChild("leaderstats")
local cash = leaderstats.Cash

game.StarterGui.GUI.Frame.TextBox.Visible = false


if cash.Value >= 1 then
	game.StarterGui.GUI.Frame.TextBox.Visible = true
end 

LocalScript located in StarterPlayerScripts.

2 things,

You’re referencing StarterGui, that is the location where guis are replicated to the clients
It only checks once on runtime

You need to reference the player’s PlayerGui and to use an event that runs when the Value changes, such as Changed

For simplicity sake, It’s better if you have the localscript in the Textbox itself

local Players = game:GetService("Players")

local player = Players.LocalPlayer 
local leaderstats = player:WaitForChild("leaderstats")
local cash = leaderstats:WaitForChild("Cash")

local textbox = script.Parent

local function update(value)
	textbox.Visible = value >= 1
end

update(cash.Value)
cash.Changed:Connect(update)

Simplest way you can do it

1 Like

Hey there! What you are doing right now, is setting the StarterGui TextBox to visible. The thing is, StarterGui is only the starting point. When your game is started, the Gui is moved to the Player and all changed made in StarterGui won’t be visible.

What you should change is this:

local player = game.Players.LocalPlayer 
local leaderstats = player:WaitForChild("leaderstats")
local cash = leaderstats.Cash

script.Parent.Visible = false

if cash.Value >= 1 then
     script.Parent.Visible = true
end 

And place the script in the TextBox. Good luck!

Edit: @EmbatTheHybrid has also included a change event which might be what your looking for as your code only runs on startup.

1 Like

Also I got one DataStorage too but that will change only 1 time?

No, the function I mentioned will run every time the value has been changed, so if the value every goes back under 1, it will make the textbox invisible

1 Like

It works thank you :slight_smile:

1 Like