Cloning function doesn't work when a value equals to a number

I’m trying to make a function where when a number value equals a curtain number, it clones a part. But I coded it, and it doesn’t work for some reason. Here’s the code I used:

local Part = game.ServerStorage.AddPart

if game.ReplicatedStorage.CoinNumber.Value == 7 then

print("Works")

local PartClone = Part:Clone()

PartClone.Parent = workspace

end

Is this code running from the server or client?

It only checks once and your value probably wasn’t at 7 at the time the code executed. Put it in a Changed event:

coinNumber.Changed:Connect(function()
    --rest of the code
end)
1 Like

I typed in that part of the code and the output gave me an error saying, attempt to index number with ‘Changed’

Changed only works with instance(coinNumber), not value(coinNumber.Value).

oh there we go now it works. Thanks for your help!

When you’re checking if an instance is changed, ensure that you’re checking that the instance itself is changed, and not the value of it. Also ensure that the variable you’re referencing is defined.

Got it. Thanks for letting me know.