script:
local isPressed = workspace.Bools.isButtonClicked while true do wait() if isPressed then script.Parent:Destroy() end end
workspace: https://imgur.com/a/8NCxjQR
Yep, exactly as the title says -.-
Just a few things to point out...
local isPressed = workspace.Bools.isButtonClicked
This variable isPressed
has been set to the BoolValue instance and NOT the actual value that the boolean instance may be.
To get the value of the boolean it would be this...
local isPressed = workspace.Bools.isButtonClicked.Value
This will mean that isPressed
is either true or false now. What you had before meant that isPressed
was always true, because the BoolValue instance existed and that's enough to pass as true.
Your script should look a little more something like this...
while wait(1) do local isPressed = workspace.Bools.isButtonClicked if isPressed and isPressed.Value then script.Parent:Destroy() return end end
I took the initiative to have this loop only run once a second. Depending on your situation you may not need an instantaneous response and a maximum second response may suffice. Just be sparing when it comes to using loops with wait()
. Using a few is fine, but eventually they'll all add up! The additional return
line is to break the loop so that after the instance is destroyed you're not forever still checking if the button was clicked.