Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why won't the GUI change when the IntValue equals a number?

I'm using a LocalScript to change a Player's GUI if an IntValue in a Player equals a number.

The point of the script is to make a GUI visible if a player has more than 0 of an item. My script is:

player = game.Players.LocalPlayer
watermelonvalue = player.Inventory.Seeds.Watermelon.Value

if watermelonvalue >= 1 then
	print("Watermelonvalue was true")
	script.Parent.Visible = true
elseif watermelonvalue == 0 then
	script.Parent.Visible = false

The script shows the GUI if the IntValue is 1 or greater but if I change the value in the server the GUI doesn't change when the value is 0.

1 answer

✓ Accepted answer

You'll need to detect when the Value is changed. You can use the GetPropertyChangedSignal event to detect when the Value is changed.

Player = game.Players.LocalPlayer
Watermelon = Player.Inventory.Seeds.Watermelon

Watermelon:GetPropertyChangedSignal("Value"):Connect(function()
	if Watermelon.Value >= 1 then
		print("Watermelonvalue was true")
		script.Parent.Visible = true
	elseif Watermelon.Value == 0 then
		script.Parent.Visible = false
	end
end)

9 comments

0

I copied the code into my game and the GUI still shows after the Value is changed.

0

Are you changing the value on the Client or the Server?

0

On the Server

0

Oh wait I just tried it again and now it works! Thanks so much!

0

No problem.

0

Ok so when I play my game not in studio the guis don't show unless the value changes so is there anyway to to fix that?

0

Any code inside the GetPropertyChangedSignal function will only run when the value is changed. You'll need to put code outside of the function if you want it to open without having the value change.

0

Ok thanks again! Sorry for asking more question

0

No problem, if you have anymore questions feel free to ask.

This discussion is preserved as it was. New answers, comments, and votes are closed.