#Damage bug

1 messages · Page 1 of 1 (latest)

south barn
#

why this part of the script knockback player but does not deal damage:explosionPart.Touched:Connect(function(hit)
if not explosionPart then return end

    local hitCharacter = hit:FindFirstAncestorOfClass("Model")

    if not hitCharacter then return end

    local hitHumanoid = hitCharacter:FindFirstChild("Humanoid")
    local hitRoot = hitCharacter:FindFirstChild("HumanoidRootPart")

    if not hitHumanoid or not hitRoot then return end
    
    local direction = (hitRoot.Position - explosionPart.Position).Unit
    local distance = (hitRoot.Position - explosionPart.Position).Magnitude
    local strength = math.clamp(1 - (distance / radius), 0, 1)
    local force = direction * strength * 100

    local explodeBv = Instance.new("BodyVelocity")
    explodeBv.Velocity = force
    explodeBv.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
    explodeBv.Parent = hitRoot

    Debris:AddItem(explodeBv, 0.2)

    hitHumanoid:TakeDamage(config:WaitForChild("Damage").Value)
end)