Touch function isnt working?

function onTouched(hit)
	local wallvalue = hit.Parent:findFirstChild("isWall")
	if wallvalue ~= nil then

		hit:Destroy()

	end


end
script.Parent.Touched:Connect(onTouched)

so when anything touches this part the script should check if the thing that touched has that value correct? but whenever a wall touches it and has that value nothing happens to it, no errors either

Capitalize Find here. . . . . .
should read FindFirstChild.

Is the wall the one being touched or is the wall inside a model of some sort

Is the part holding this script anchored? If so, that might be why it isn’t firing, and unanchoring the part should fix the issue.

There are also ways to keep the part in place if it’s suspended in the air or has collisions disabled, such as constantly making the velocity set to (0,0,0) and making the script remember its parents initial position at the start so it for sure won’t fall.

Instead. Use GetTouchingParts.

game:GetService("RunService").Heartbeat:Connect(function()
    local func = script.Parent.Touched:Connect(function() end)
    local result = part:GetTouchingParts()
    func:Disconnect()
    for i,hit in pairs(result) do
        if hit.Parent:FindFirstChild("isWall") then
            hit:Destroy()
        end
    end
end)

Put this in the same spot. This will also detect anchored parts, and nocollided parts (or should) Have fun!

1 Like

the wall is in a model ᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼