Need Help Fixing Hitbox Detection for a Rolling Log

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve?

I want to make sure that players only take damage when they actually touch the rolling log. If they jump over it or are not in direct contact, they should not take damage.

  1. What is the issue?

(The red part is the Hitbox.)

Right now, players take damage even when they are not touching the log. If they jump and the log rolls underneath them, they still take damage, even though there is no actual contact.

  1. What solution have you tried so far?

• Used a Hitbox part instead of detecting collisions on the entire log.

• I tried to look for alternatives on the DevForum, but I didn’t understand most of them as I’m still learning and an intermediate scripter

local logDamage = 5
local logDamageDebounce = .25

local debounce = false

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") and not debounce then
		debounce = true
		local plr = game.Players:GetPlayerFromCharacter(hit.Parent)

		plr.Character.Humanoid:TakeDamage(logDamage)

		print("Plr took damage")

		task.wait(logDamageDebounce)
		debounce = false
	end
end)
local logDamage = 5
local logDamageDebounce = 0.25
local hitbox = script.Parent

local function applyDamage()
    for _, part in ipairs(hitbox:GetTouchingParts()) do
        local character = part.Parent
        local humanoid = character:FindFirstChild("Humanoid")
        
        if humanoid then
            humanoid:TakeDamage(logDamage)
            print("Player took damage")
            task.wait(logDamageDebounce)
        end
    end
end

-- # Use Heartbeat to frequently check for collisions
game:GetService("RunService").Stepped:Connect(function()
    applyDamage()
end)

Hey, thanks for the script! I tried it but it’s not working. The player doesn’t take any damage at all.

You should make the collisions be client-sided.

So should I just change the script’s Runcontext to client?

I guess that would work? I never really checked out RunContext.

It looks like it’s working! Tysm.