Hi everyone, I've made an hammer tool and I want it to knockback players whenever I tap the screen or click my mouse.

This is the code I have currently:

local Player = game.Players:GetChildren().Character
local hammer = script.Parent.Parent
local handle = script.Parent
hammer.CanBeDropped = false
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 = 1 -- How long in seconds the knockback lasts
 


hammer.Equipped:Connect(function(Mouse)
    Mouse.Button1Down:Connect(function(hit)
        knockbackPart.Touched:Connect(function(part)
    		local force = knockbackPart.Position * knockbackMultiplier
    		local bodyForce = Instance.new("BodyForce", part)
    		bodyForce.Force = force
    		wait(knockbackDuration)
    		bodyForce:Destroy()
			script.Disabled = true
			wait(2)
			script.Disabled = false
		end)
    end)
end)

It doesn't work and I'm trying for hours to figure out what to do, I know it's easy but I'm a starter so yeah.

Image of the tool: https://imgur.com/a/h9gZuNa

2 comments

0

I forgot how to do this but you're gonna have to set the BodyForce's properties higher. Go read into it. I know its properties affect how much force is exerted

0

Yeah problem is it's only working when I'm touching a player with my hammer and it's knocking me back, not others..