Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to add knockback to tool?

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?

3 comments

0

BodyVelocity on touch.

0

Sorry but I dont understand

0

What he means is when the tool is touched put a BodyVelocity into the humanoid root part of the target player

2 answers

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)

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.