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

How to make a sword do knockback?

Hows might I make a sword do some knockback to an AI enemy? I think it has something to do with CFrame but am not to sure, my sword script is this:

local enemies = game.Workspace.Enemies:GetChildren() --// All the children of the enemies folder.


for i, v in pairs(enemies) do
        if v:FindFirstChild("Zombie") then --// If the model has a humanoid
            wait(1)
            v.HumanoidRootPart.Touched:Connect(function()--// When the sword touches the npc
                script.Parent.Activated:Connect(function() --// If you click holding the sword it will damage.
                v.Zombie:TakeDamage(10) --// Npc takes 10 Damage
                wait(1)
            end)
            end)
            end
    end
    

2 comments

0

ok so what is the problem of this, because I can't anser you if you don't share the problem. Have you tested it?

0

yes, I have, this works fine but how would I make it do knockback to what the sword touches?

1 answer

✓ Accepted answer

You could try using Velocity.

This makes the local player's Character move a few studs backwards:

game.Players.LocalPlayer.Character.HumanoidRootPart.Velocity = game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame.LookVector*-100

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