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

How can I make a brick to be destroyed depending on a value?

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()

1 answer

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!

2 comments

0

I think the wait(0) might be unnecessary. And there's no need to call dirt() before connecting it.

0

It would be best if it was >= 0 just incase it skips over 0 before it deletes the block.

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