Trying to make a potion counter GUI

So, I’m trying to make a counter on the screen to tell the player how many health potions they have. I’m a complete noob when it comes to scripting, but I tried to make this script to change the text of the text label to be the value of a number value.

Potions = script.Parent:FindFirstChild("Potions")

script.Parent.Text = Potions.Value

This did not work. And I, being the absolute noob I am, have no idea what I did wrong. Any help would be appreciated.

2 Likes

You want to setup a changed event to the potions number value. This will fire whenever the value of the potions change.

Something like this may work -

Potions = script.Parent:FindFirstChild("Potions")
Potions.Changed:connect(function()
    script.Parent.Text = Potions.Value
end)

I recommend reading more on the changed event as it is very useful when making counters

1 Like

The script still doesn’t work : / I have the value set to 1 and the text on the label set to 0, but when I test the game it stays 0 and does not change to one.

I would do is to put that line in a while true do loop like this:

while true do
     wait(.5)
     script.Parent.Text = Potions.Value
end

This would make it so it constantly checks on the value and updates the GUI, please make sure to add the wait() otherwise your studio might crash.

I hope this helps! Please reply to me and tell me what is wrong, have a good day!

1 Like

Another thing I want to make sure you know, this also can depend on where you are storing your variable, if you are storing the potion variable in the text GUI then this script will not work. You could store it in workspace or maybe inside of the player.

2 Likes

I tested this in Roblox Studio and it worked, I had a while true do loop changing the value for this so as long as value is changed you should be fine.

local Potions = script.Parent:FindFirstChild("Potions")

Potions:GetPropertyChangedSignal("Value"):Connect(function()
	script.Parent.Text = Potions.Value
end)
1 Like

Has any of these worked for you? Just wondering.

1 Like

I’ve been trying and none of them have been working. I’m probably doing something wrong, but I will just figure it out on my own. Thank you for the help, though.

Mine worked perfectly, you’re doing something wrong.

1 Like

I’m sorry to hear that, if you need any more help feel free to ask. I know @uhBlame and mine work. (:

1 Like

Check out this video of me showing that it works for me
https://streamable.com/mwclc2
Maybe check your script for errors, or the script in general you can send it here for we can review it.

1 Like

The video helped a lot, and I got it working. Thank you so much for your time