What is wrong with my script that makes parts appear and disappear when reaching a certain number in an intvalue?

Sorry for the long title.
I made a script that makes parts of a model appear when a certain number in an intvalue is reached
( > 9) and I’ve been trying to make the parts disappear when the intvalue is reset ( < 9), but nothing seems to be working. (There are no errors)

Can anyone help?

script:

local tencoin = script.Parent.tencoin
local Currency = script.Parent.Parent.Parent.CurrencyToCollect

for i,v in pairs(tencoin:GetChildren()) do
v.Transparency = 1
Currency.Changed:Connect(function(NewValue)
if NewValue > 9 then
v.Transparency = 0

		if NewValue < 9 then
			v.Transparency = 1
		end
	end
end)

end

(Hello, My answer could be wrong because i’m still learning lua but i’ll try to be helpful ;3 )
Srry i’m bad at english but do you want the loop to run every time when the value changes if so try

local tencoin = script.Parent.tencoin
local Currency = script.Parent.Parent.Parent.CurrencyToCollect
Currency.Changed:Connect(function(NewValue)
for i,v in pairs(tencoin:GetChildren()) do
	v.Transparency = 1

		if NewValue > 9 then
			v.Transparency = 0

			if NewValue < 9 then
				v.Transparency = 1
			end
		end
	end
end)
1 Like

Your version of the script works! Thank you so much for your help!

1 Like