.Touched Collisions don't register

I’ve done digging from my script which has led me to conclusions that my ‘lava’ does not collide with any parts of the HQ. However, it registers collisions with characters.
(The script does get enabled if you happen to wonder)

local tweenService = game:GetService("TweenService")
local lava = script.Parent.Lava

local debounce = false
lava.Touched:Connect(function(hit)
    if debounce then return end
    print("uh1")
    print(hit:GetFullName())
    print(workspace:FindFirstChild("CanBurn", true):GetFullName())
    print(hit.Parent:FindFirstAncestor("CanBurn") ~= nil)
    if hit and hit.Parent:FindFirstChildWhichIsA("Humanoid") then
        debounce = true
        hit.Parent.Humanoid.Health -= 10
    elseif hit:FindFirstAncestor("CanBurn") then
        print("uh2")
        task.spawn(collapse, hit)
    end
    debounce = false
end)

function collapse(part)
    print("YO UH")
    tweenService:Create(part, TweenInfo.new(5), {Transparency = 1, Color = Color3.fromRGB(0, 0, 0)}):Play()
    for _, v in part:GetTouchingParts() do
        task.spawn(collapse, v)
    end
    part.Anchored = false
    game.Debris:AddItem(part, 5)
end

tweenService:Create(lava, TweenInfo.new(50, Enum.EasingStyle.Quint), {Size = Vector3.new(118.5, 27.7, 99.3), CFrame = CFrame.new(83.25, 80.55, -29.95)}):Play()


Try changing

if debounce then return end

to

if debounce == true then return end

might work hopefully
image
(as you can see here from testing if false and if true both printed hi, meaning that its most likely just a logic error.)

That output displays that you ran the false logic twice, not the hi being printed twice.

if debounce then return end just means if debounce ~= nil and debounce ~= false then return end which since debounce is a boolean, the only way to satisfy the logic is if debounce is equal to true, so that wouldn’t make a difference.

Is the lava and the HQ building both Anchored? Touches only register between Parts if at least one if them is unanchored during their physics simulation.

Really? Let me try unanchoring one of 'em.

You should use :GetPartBoundsInBox() to do this, Part.Touched is a very bad event to use for hitboxes, you can use a loop that checks all the parts colliding with the lava and unanchor them or kill them if they are a player, example code:

-- Lava Script

local LavaPart = script.Parent

while true do
	local CollidingParts = game.Workspace:GetPartBoundsInBox(LavaPart.CFrame, LavaPart.Size)
	
	for PartI, Part in pairs(CollidingParts) do
		if Part ~= LavaPart then
			local Humanoid = Part.Parent:FindFirstChildOfClass("Humanoid")

			if Humanoid then
				Humanoid:TakeDamage(25)
			else
				Part.Anchored = false
				Part:BreakJoints() -- Removes all welds connected to this part.
			end
		end
	end
	
	task.wait(0.1)
end

I’ve got this:

local tweenService = game:GetService("TweenService")
local lava = script.Parent.Lava

local function collapse(part)
    if part.Parent == script.Parent.Burned then return end
    if not part:FindFirstAncestor("CanBurn") then return end
    part.Parent = script.Parent.Burned
    tweenService:Create(part, TweenInfo.new(5), {Transparency = 1, Color = Color3.fromRGB(0, 0, 0)}):Play()
    for _, v in part:GetTouchingParts() do
        task.spawn(collapse, v)
    end
    part.Anchored = false
    game.Debris:AddItem(part, 5)
end

task.spawn(function()
    while task.wait(0.1) do
        local collisions = workspace:GetPartBoundsInBox(lava.CFrame, lava.Size)

        for _, v in collisions do
            if v ~= lava then
                if not v then continue end
                    if v.Parent:FindFirstChildWhichIsA("Humanoid") ~= nil then
                        v.Parent:FindFirstChildWhichIsA("Humanoid").Health -= 5
                    else
                        task.spawn(collapse, v)
                    end
                end
            end
        end
    end
end)
tweenService:Create(lava, TweenInfo.new(50, Enum.EasingStyle.Quint), {Size = Vector3.new(118.5, 27.7, 99.3), CFrame = CFrame.new(83.25, 80.55, -29.95)}):Play()

Now for some reason it says line 29: attempt to index nil with FindFirstChildWhichIsA("Humanoid") even when I put a non-existence check.

Make sure Part.Archivable is set to true:

task.spawn(function()
    while task.wait(0.1) do
        local collisions = workspace:GetPartBoundsInBox(lava.CFrame, lava.Size)

        for _, v in collisions do
            v.Archivable = true -- Makes sure Archivable is set to true.
            if v ~= lava then
                if not v then continue end
                    if v.Parent:FindFirstChildWhichIsA("Humanoid") ~= nil then
                        v.Parent:FindFirstChildWhichIsA("Humanoid").Health -= 5
                    else
                        task.spawn(collapse, v)
                    end
                end
            end
        end
    end
end)

Same error occurs, I even made sure it was all archivable before the map clones. For context, the script (disabled) is in the map and when cloned, is automatically enabled.

You should use ZonePlus. It’s a module very simple to use that allows you to check for hitboxes and based on this you can take certain actions like killing the player or damaging it.

I tried it in my studio, I edited some things and this works fine for me:

local tweenService = game:GetService("TweenService")
local lava = script.Parent.Lava

local function collapse(part)
	if part.Parent == script.Parent.Burned then return end
	--if not part:FindFirstAncestor("CanBurn") then return end
	part.Parent = script.Parent.Burned
	tweenService:Create(part, TweenInfo.new(5), {Transparency = 1, Color = Color3.fromRGB(0, 0, 0)}):Play()
	if part ~= lava then
		part.Anchored = false
	end
	game.Debris:AddItem(part, 5)
end

task.spawn(function()
	while task.wait(0.1) do
		local collisions = workspace:GetPartBoundsInBox(lava.CFrame, lava.Size)
		
		for _, v in pairs(collisions) do
			v.Archivable = true
			if v ~= lava then
				if not v then continue end
				if v.Parent:FindFirstChildWhichIsA("Humanoid") ~= nil then
					v.Parent:FindFirstChildWhichIsA("Humanoid").Health -= 5
				else
					task.spawn(collapse, v)
				end
			end
		end
	end
end)

Is it a Local Script?

afafafafafa

Oh, hi! I remember you almost half a month ago! Nope, server-sided.

1 Like

I remember you, too! Try to print hit.

1 Like

Actually you already did nevermind

1 Like

I’ll send a video of the bug but it needs to be approved first.

Taking a while…

Try checking if the parent is nil or not, I had a problem similar to this before and I fixed it by doing that.

Checking if the object is nil doesn’t work anymore I think.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.