Why won't the block destroy?

I am making a building and destroying system, but when I try to destroy the part it doesn’t destroy it even though when I check if a value is false and I know it is false it won’t pass the if statement, am I missing something very obvious?

Video of problem
robloxapp-20200906-2309091.wmv (1.1 MB)

local script

local function destroyBlock()
	print(isPlacing, canPlace) -- when I print it it is equal to false, yet it doesn't pass the if statement below
	if isPlacing and canPlace == false then
		print("sdfg") -- this won't print
		if mouse.Target ~= nil then
			if mouse.Target.Parent == workspace.Blocks then
				if (player.Character.HumanoidRootPart.Position - mouse.Target.Position).magnitude <= 18 then
					mouse.Target:Destroy()
				end
			end
		end
	end
end

mouse.Button1Up:Connect(destroyBlock)
1 Like

fun fact:

it’s better to use not canPlace instead of canPlace == false. this won’t really contribute to your problem but just a random tip!

why is it better if they mean the same thing?

is the block a model with parts inside or just a part?

It is just a part with 6 decals

i recall someone telling me that not is usually better than == false, but i don’t really remember the reason.

here you should check the target’s parent like this:

if mouse.Target.Parent == "Blocks" then

That is not the if statement that it gets stuck on it gets stuck on

if isPlacing and canPlace == false then

What is isPlacing printing? In the if statement you are checking if isPlacing is true and canPlace is false. Are both of them false because if you want to check if both of them are false then you would do:
if isPlacing == false and canPlace == false then

1 Like