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

What is wrong with my script?

Asked by
Prioxis 673 Moderation Voter
10 years ago

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

Log in to vote
0
Answered by 10 years ago

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!

Ad

Answer this question