Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 4 years ago
Edited 4 years ago

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

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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)
0
I copied the code into my game and the GUI still shows after the Value is changed. TestUser4646 1 — 4y
0
Are you changing the value on the Client or the Server? xInfinityBear 1777 — 4y
0
On the Server TestUser4646 1 — 4y
0
Oh wait I just tried it again and now it works! Thanks so much! TestUser4646 1 — 4y
View all comments (5 more)
0
No problem. xInfinityBear 1777 — 4y
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? TestUser4646 1 — 4y
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. xInfinityBear 1777 — 4y
0
Ok thanks again! Sorry for asking more question TestUser4646 1 — 4y
0
No problem, if you have anymore questions feel free to ask. xInfinityBear 1777 — 4y
Ad

Answer this question