My script runs an if statement even if what it needs doesn't happen

I have been testing out an idea and I found something strange with how my script is working. I want to make a simple if statement where if you click a block it prints “Clicked” and if not it prints "NotClicked’

however, it runs even though its not supposed to

local PlantBox = script.Parent
local Soil = PlantBox.Soil
local BoxFrame = PlantBox.BoxFrame
local ClickDetector = PlantBox.Soil.ClickDetector

--If the Box is clicked
if ClickDetector.MouseClick then

I don’t know why this is happening so any help would be appreciated.

MouseClick is an event.

	--code for when clicked.

Your script is currently checking whether if a property called “mouseclick” exists under ClickDetector, and since it does exist, the if statement is considered affirmative and hence is getting executed…

So you’d have to use the :Connect statement as mentioned above in the previous post

Goodluck and godspeed with your game!

1 Like

Why did you make an if statement for that? Make it an event.

1 Like

After realizing that ClickDetector.MouseClick is an event I set it to check if it was true or not, thanks to everyone bellow I was able to come to this conclusion.