This is my simple script, and the issue I’m facing is that the “Block” immediately destroys itself without needing to Click on the Click Detector that destroys the Block. In this If statement, the block shouldn’t destroy itself until the Click Detector is clicked. Help?
The reason is due to the way your using the .MouseClick event. Your using it in an if statement which is incorrect and rather you should be connecting the .MouseClick up with a function rather then putting it inside of an if statment.
Right, but I only want it to only ever happen once, so I used an if statement instead of a function.
Shouldn’t it still refrain from being destroyed until the “if” part is completed?
I would use a function if it was a repetitive task.
Destroy the clickdetector in the function
Try instead:
clickDetector.MouseClick:Connect(function()
block:Destroy()
end)
You can’t use the MouseClick event in that if statement like this.
You still would, that’s the only way to actually detect when it’s pressed lol.
My real question is why isn’t the if statement working in this case?
That still does not fix the issue of that you can’t use an if statement with an event. You should do what @TheLazyRaven said or you could have the script inside of the block so when the block is destroyed the script is destroyed as well.
Because that is not how events and if statements work. The only real way you can run something on the fire of an event is via connecting it up with a function. You could have value which if it’s false it destroys the block and if it is true you don’t or just destroy the script or something else like that.
