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

How to make a sword do knockback?

Asked by
zomspi 541 Moderation Voter
4 years ago

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


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? TheRealPotatoChips 793 — 4y
0
yes, I have, this works fine but how would I make it do knockback to what the sword touches? zomspi 541 — 4y

1 answer

Log in to vote
0
Answered by
ryan32t 306 Moderation Voter
4 years ago

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
Ad

Answer this question