I'm trying to make the GUI Update every time the value is changed using the changed function but it keeps erroring out
Here's my script:
local Candy = game.Players.LocalPlayer.Pumpkins Candy.Value.Changed:connect(function(ValChanged) script.Parent.Text = "Candy Collected: "..Candy.." / 25" end)
When you use the Changed
event, it is an event of the object itself, not of the properties. So when you use the Changed
event on "Candy", it has to be an event of "Candy", not of its value. So the correct way to write your code would be like this:
local Candy = game.Players.LocalPlayer:WaitForChild("Pumpkins") --Added a WaitForChild to prevent erroring Candy.Changed:connect(function() --Removed the ".Value" and the "ValChanged" script.Parent.Text = "Candy Collected: "..tostring(Candy.Value).." / 25" --"Candy" by itself has no value, only the "Value" property of Candy has a value end)
Hope this helped!