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

How do you add a simple knockback system to a tool?

Asked by 4 years ago

This is how I did it but it doesn't work. Please help, thank you! <3

local tool = script.Parent
local head = tool.Head
local swinging = false

tool.Activated:Connect(function()
    local humanoid = tool.Parent:FindFirstChild("Humanoid")

    if humanoid then
        local smash = tool.Smash
        local smashTrack = humanoid:LoadAnimation(smash)

        smashTrack:Play()
    end

    swinging = true
    wait(2)
    swinging = false
end)

head.Touched:Connect(function(hit)
    local humanoid = hit.Parent:FindFirstChild("Humanoid")
    if humanoid and swinging then
        local bodyVelocity = Instance.new("BodyVelocity")
        bodyVelocity.MaxForce = Vector3.new(1000,1000,1000)
        bodyVelocity.Velocity = (humanoid.HumanoidRootPart.CFrame.LookVector) * 100
        bodyVelocity.Parent = humanoid.HumanoidRootPart
    end
end)

Answer this question