#Linear velocity doesn't work because I added a part

1 messages · Page 1 of 1 (latest)

humble scroll
#
function module.linearVelocity(hrp, knockback, type)


    local linearVelocity = Instance.new("LinearVelocity", hrp)
    linearVelocity.Attachment0 = hrp:WaitForChild("RootAttachment")
    linearVelocity.MaxForce = 100000
    linearVelocity.RelativeTo = Enum.ActuatorRelativeTo.Attachment0
    
    if type == "enemy" then
        linearVelocity.VectorVelocity = knockback
    elseif type == "player" then
        
        local trackingBox = Instance.new("Part", game.Workspace)
        trackingBox.Size = Vector3.new(7,7,7)
        trackingBox.CanCollide = false
        trackingBox.CanQuery = false
        trackingBox.CanTouch = false
        trackingBox.Transparency = 0.5
        trackingBox.Color = Color3.new(1, 0, 0)
        trackingBox.CFrame = hrp.CFrame
        trackingBox.Anchored = false

        local weld = Instance.new("WeldConstraint", trackingBox)
        weld.Part0 = hrp
        weld.Part1 = trackingBox
        
        linearVelocity.VectorVelocity = Vector3.new(0,0,knockback)
        
        trackingBox.Touched:Connect(function(hit)
            local hitChar = hit.Parent
            if hit.Parent:FindFirstChild("Humanoid") and hit.Parent ~= hrp.Parent then
                linearVelocity:Destroy()
                hit.Parent.Humanoid.WalkSpeed = 0
                hit.Parent.Humanoid.JumpHeight = 0
                trackingBox:Destroy()
            end
        end)
        
    end
    Debris:AddItem(linearVelocity, 0.2)

end```
#

How can I fix this? the tracking box is there to detect if a player during the dash and stun them and i needed a bigger detection area than just the hrp itself

#

maybe there's a more efficient way to do this?

warped laurel
#

ake the tracking box masless

humble scroll
#

.touched was very inconsistent

warped laurel
#

yeah

#

make sure you use overlap params of else if it overlaps alot of parts it can cause server lag since its looping through them all