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

What is wrong with my script?

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)

1 answer

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!

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