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

Why doesnt this work?

Asked by 8 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

I have some code and I don't know why it doesn't work. Help?

t = script.Parent.Parent.Parent.CurrencyToCollect.Value
function MoneyBin()
script.Parent.Treasure:ClearAllChildren()
if t > 0 and t <= 500 then
    game.Lighting.t1:Clone().Parent = script.Parent.Treasure
elseif t > 500 and t <=1000 then
    game.Lighting.t2:Clone().Parent = script.Parent.Treasure

end
end

script.Parent.Parent.Parent.CurrencyToCollect.Changed:connect(MoneyBin)

1 answer

Log in to vote
0
Answered by
Im_Kritz 334 Moderation Voter
8 years ago

I believe the problem is your code states the value currency before hand. The code doesn't re-check for if the currency each time the event is fired. Therefore, the script just thinks the currency is 0 or whatever the starting value is.

How to fix this is removing the .Value off the variable and the if statement needs to check for the new currency value each time it gets fired.

local t = script.Parent.Parent.Parent.CurrencyToCollect
function MoneyBin()
script.Parent.Treasure:ClearAllChildren()
if t.Value > 0 and t.Value <= 500 then
    game.Lighting.t1:Clone().Parent = script.Parent.Treasure
elseif t.Value > 500 and t.Value <=1000 then
    game.Lighting.t2:Clone().Parent = script.Parent.Treasure

end
end

script.Parent.Parent.Parent.CurrencyToCollect.Changed:connect(MoneyBin)

Ad

Answer this question