Currently trying to make a Knockback system for a bat tool, but the dummy won’t move at all. Here is the code:
function module.Knockback(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local char = hit.Parent
local HRP = char:FindFirstChild("HumanoidRootPart")
if HRP then
local Speed = 100
local TotalForce = 80000
local KnockBack = Instance.new("BodyVelocity")
KnockBack.Parent = HRP --part is the target of the knockback/ the opponent
KnockBack.MaxForce = Vector3.new(TotalForce,TotalForce,TotalForce)
KnockBack.Velocity = char:FindFirstChild("HumanoidRootPart").CFrame.LookVector *- Speed
task.wait(0.3)
KnockBack:Destroy()
end
end
end
I got it to work with the anchor thing, thanks. Another problem though, when I throw the player, its very buggy and only throws the play in 1 position.
So you would need your own character’s humanoidrootpart lookvector
To do so, find your character somehow in workspace and find its HRP lookvector.
So the direction your character faces is the knockback direction.
Nvm… I’ve modified it, but the player will just go up and down and doesn’t move in any direction
function module.Knockback(plr_who_swung, hit)
if hit.Parent:FindFirstChild("Humanoid") then
local char = hit.Parent
local HRP = char:FindFirstChild("HumanoidRootPart")
if HRP then
local lv = plr_who_swung.Character.HumanoidRootPart.CFrame.LookVector
local Speed = 100
local TotalForce = 80000
local KnockBack = Instance.new("BodyVelocity")
KnockBack.Parent = HRP
KnockBack.MaxForce = Vector3.new(TotalForce, TotalForce, TotalForce)
KnockBack.Velocity = char:FindFirstChild("HumanoidRootPart").CFrame.LookVector * lv
HRP.Position += Vector3.new(0, 2, 0)
task.wait(0.2)
KnockBack:Destroy()
end
end
end
Again the same problem, the player doesn’t move whatsoever. Here is the full code I used:
function module.Knockback(plr_who_swung, hit, part)
if hit.Parent:FindFirstChild("Humanoid") then
local char = hit.Parent
local HRP = char:FindFirstChild("HumanoidRootPart")
if HRP then
local lv = plr_who_swung.Character.HumanoidRootPart.CFrame.LookVector
local LV = char:FindFirstChild("HumanoidRootPart").CFrame.LookVector * lv
local Speed = 100
HRP:ApplyImpulse(LV*Speed)
end
end
end
function module.Knockback(plr_who_swung, hit, part)
if hit.Parent:FindFirstChild("Humanoid") then
local char = hit.Parent
local HRP = char:FindFirstChild("HumanoidRootPart")
if HRP then
local lv = plr_who_swung.Character.HumanoidRootPart.CFrame.LookVector
local LV = char:FindFirstChild("HumanoidRootPart").CFrame.LookVector * lv
local Speed = 100
HRP:SetNetworkOwner(nil)
HRP:ApplyImpulse(LV*Speed)
task.wait(3)
HRP:SetNetworkOwner(game.Players:GetPlayerFromCharacter(HRP.Parent)
end
end
end
Try firing a remoteevent to send the client the Vector3 value for the “ApplyImpulse” then use the apply impulse through the client side. I understand that this could be exploited, but you may be able to come up with a way to stop this?
I don’t think this idea is very plausible. Sending a remote event to the client would be kinda dumb since only that client would be able to see the player moving. I want the entire force system / damage system to be fully server sided, so no exploits can be made.