Hello! I was recently working on a tps framework, i tried to do a knockback system, and i was trying to make it so LinearVelocity accumulates speed, as multiple LinearVelocities in a HumanoidRootPart doesn’t accumulate. But then, this happened:
This is in the code, it’s a remote that is executed in the victim’s client when it gets attacked:
local totalKnockback = Vector3.new()
local function onCharacterKnockback(attacker)
if not plr.Character or not attacker.Character then return end
local knockbackPower = 40
local direction = (plr.Character.HumanoidRootPart.Position - attacker.Character.HumanoidRootPart.Position).Unit
local char = plr.Character
print("executing remote")
local force = 800000000
if plr.Character.HumanoidRootPart.Velocity.Magnitude > 0.1 then
warn("Char magnitude:", plr.Character.HumanoidRootPart.Velocity.Magnitude)
plr.Character.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Physics, false)
plr.Character.HumanoidRootPart.Velocity = Vector3.new(0,0,0)
plr.Character.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Physics, true)
end
local att = char.HumanoidRootPart:FindFirstChild("KBAttachment")
local kbVelocityIns = char.HumanoidRootPart:FindFirstChild("KBLinearVelocity")
if att then att:Destroy() end
if kbVelocityIns then kbVelocityIns:Destroy() end
local att = Instance.new("Attachment")
att.Name = "KBAttachment"
att.Parent = plr.Character.HumanoidRootPart
totalKnockback += direction * knockbackPower
task.spawn(function()
wait(0.02)
totalKnockback -= direction * knockbackPower
end)
print(totalKnockback)
local kbVelocityIns = Instance.new("LinearVelocity")
kbVelocityIns.Name = "KBLinearVelocity"
kbVelocityIns.Attachment0 = att
kbVelocityIns.Parent = plr.Character.HumanoidRootPart
kbVelocityIns.MaxForce = force
kbVelocityIns.VectorVelocity = totalKnockback
print(kbVelocityIns.VectorVelocity)
Debris:AddItem(kbVelocityIns, 0.04)
Debris:AddItem(att, 0.04)
end
Also, i’ve tried to replace totalKnockback and instead, just use (direction * knockbackPower) in the VectorVelocity, and it works, but it keeps being only one knockback at a time, and that’s not the idea
If there’s another way around to make accumulable LinearVelocity please help, as i haven’t found any topic in the DevForum about this…