My damage system / Touched event not working?

My damage system will not work. Here is my code: (serverside)

local object = game.ReplicatedStorage.Hitbox:Clone()
object.Parent = workspace
object.CFrame = char:FindFirstChild("Wooden Katana").Handle.CFrame
object.Orientation = char:FindFirstChild("Wooden Katana").Handle.Orientation
debris:AddItem(object, .5)

local weld = Instance.new("WeldConstraint")
weld.Parent = object
weld.Part0 = object
weld.Part1 = char:FindFirstChild("Wooden Katana").Handle

local hit = false
object.Touched:Connect(function(part)
    print("hello")
    if not hit and not part:IsDescendantOf(char) then
        local humanoid = part.Parent:FindFirstChild("Humanoid")
        if humanoid then
            hit = true
            print("test")
            wait()
            hit = false
        end
    end
end)

Gif of my script being ran:
https://gyazo.com/c975d1b817c1bbaa4c23f28386a0b083

The empty output:

1 Like
 if humanoid then
            hit = true
            print("test")
            wait()
            hit = false
        end

I can’t see the damage line, where is it?

The problem is the script doesn’t print anything.

Could it be that the object disappears too soon? Try changing AddItem() 2nd argument to a higher value

I’m not so sure about this, but doesn’t object get destroyed before it is able to touch anything because of debris:AddItem(object, .5)?

Maybe does object is nil?

30chars

This is a common problem with using Touched for hitboxes. Remember that Touched only fires when it intersects parts physically. When a hitbox is spawned like this, for whatever reason, it’s not registered as touching against the target character.

When it comes to Touched-based hitboxes, you really have to resort to odd tricks in order for it to function correctly. One such trick is to add a negligible amount of velocity (either via Part.Velocity or a body mover) to an unwelded hitbox and position it such that it’s relatively in the same vicinity as where the weapon can be swung around.

Some other methods I’ve seen don’t involve Touched, but instead look at raycasting and distance-based damage (typically for games where it doesn’t matter if the sword doesn’t actually hit you).

1 Like

the object isn’t nill and i removed the additem, same issue.

Does this will only get the katana cframe once?

yes it only gets the cframe only once

Maybe it’s because of that, the script is only getting the Katana’s CFrame once, and it’s not moving with the Katana (as i think it should work) and since it’s not getting hit by the player, nothing is getting printed.

nevermind, i figured out the issue. apparently all i had to do was do instance.new instead of cloning the parts.