Help with Detecting Brick Collision

I am trying to stop the truck from moving whenever it collides with a part or humanoid. The problem is that the truck goes through the brick wall but stops when it collides with the humanoid.


download

This is my code so far:

local truck = script.Parent
local drive = true

truck.mainPart.Touched:Connect(function(hit)
	if hit:IsA("BasePart") or hit:IsA("Model") or hit.Parent:FindFirstChild("Humanoid") then
		drive = false
		print("Touched")
	end
end)

while drive do
	truck:SetPrimaryPartCFrame(truck:GetPrimaryPartCFrame() * CFrame.new(0,0,0-.1))
	wait()
end

What should I do to fix this?

The reason for this is because the touch event is rather particular. It requires at least one of the parts to have collision enabled, and it won’t trigger with CFrame or position updates if it’s anchored, unless the other part is unanchored.

However, the touch event doesn’t need to be used. Instead, I would recommend using Region3. Specifically, Rotated Region3 by EgoMoose.