Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to add knockback to tool?

Asked by 5 years ago

Im making minigames game and I would like to make minigame where players try to deal knockback to each others so other players would fall off the platform. And last one standing wins. But I dont know how to add Knockback for tool. Is it even possible? If yes, how?

0
BodyVelocity on touch. DemonEyee 55 — 5y
0
Sorry but I dont understand PoometryPython -5 — 5y
0
What he means is when the tool is touched put a BodyVelocity into the humanoid root part of the target player Fad99 286 — 5y

2 answers

Log in to vote
0
Answered by
bjr29 40
5 years ago

This code won't be the best but it should just about work. It doesn't always throw the player or object but it does most of the time. How hard it's hit also affects the knockback given.

local knockbackPart = script.Parent -- When it's hit, it creates knockback on what hit it
local knockbackMultiplier = 10 -- How strong the knockback is
local knockbackDuration = .5 -- How long in seconds the knockback lasts  

knockbackPart.Touched:Connect(function(part)
    local force = knockbackPart.Position * knockbackMultiplier
    local bodyForce = Instance.new("BodyForce", part)
    bodyForce.Force = force

    wait(knockbackDuration)
    bodyForce:Destroy()
end)
Ad
Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

Hey look ik this was back in 2019 But here:

-- // Knock Back System \\
local Fist = script.Parent -- // [Fist] Is A Tool

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()


local function Fist_Swung()

  local HumanoidRootPart = Mouse.Target:FindFirstChild("HumanoidRootPart")
  local KnockBack = Vector3.new(5, 5, 5)

  if HumanoidRootPart then
     local KnockBackActivate = HumanoidRootPart.Position * KnockBack

     HumanoidRootPart.Position = KnockBackActivated
  end 

  return KnockBackActivate

end


Tool.Activated:Connect(Fist_Swung)

Answer this question