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

Why doesnt this work?

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

✓ Accepted answer

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)

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