I have a brick with an IntValue inside. If the value is 0 then the brick would be destroyed. I've tried this but its not working:
function dirt()
if script.Parent.Value == 0 then
wait(0)
script.Parent:Destroy()
end
end
dirt()
I have a brick with an IntValue inside. If the value is 0 then the brick would be destroyed. I've tried this but its not working:
function dirt()
if script.Parent.Value == 0 then
wait(0)
script.Parent:Destroy()
end
end
dirt()
Well, you defined the function for determining the value, but it does not apply to change. What I mean is you also need to connect the value's Changed event to keep the function updated.
The fix is easy, you just have to add a new line of code!
function dirt()
if script.Parent.Value <= 0 then -- In case the number is under or exactly 0...
script.Parent:Destroy()
end
end
dirt()
script.Parent.Changed:Connect(dirt) -- Make the script apply the function to the value's change!
Any questions? Please leave a comment below. Thanks!
This discussion is preserved as it was. New answers, comments, and votes are closed.
2 comments
I think the wait(0) might be unnecessary. And there's no need to call dirt() before connecting it.
It would be best if it was >= 0 just incase it skips over 0 before it deletes the block.