#Need help with knockback animation

1 messages · Page 1 of 1 (latest)

fallen turtle
#

I apologize if this has been asked before, I'm trying to play a knockback animation that changes the position of the hit humanoid by 7 studs or so behind. However since the animation does not actually change the position of the humanoid I'm attempting to change the humanoid position after the animation is done.

#

local ReplicatedStorage=game:GetService("ReplicatedStorage")
local Sounds=ReplicatedStorage.Sounds:GetChildren()
local CombatEvent=ReplicatedStorage:WaitForChild("Combat")
local Debris=game:GetService("Debris")
local HitAnimation=ReplicatedStorage.Animations:WaitForChild("Hit")
local DamageValues={10,15,20}

#

CombatEvent.OnServerEvent:Connect(function(Player,Combo)
Sounds[1]:Play()
local Character=Player.Character
local HitBoxCooldown=2
Character.Humanoid.WalkSpeed=10
task.delay(2,function()
Character.Humanoid.WalkSpeed=16
end)

local Hitbox=Instance.new("Part")
Hitbox.Size=Vector3.new(7,7,7)
Hitbox.Transparency=1
Hitbox.CanCollide=false
Hitbox.Anchored=true
Hitbox.Parent=workspace
Hitbox.BrickColor=BrickColor.new("Bright red")
Hitbox.CFrame=Character.HumanoidRootPart.CFrame+Character.HumanoidRootPart.CFrame.LookVector*5
#

local function Hit(HitPart)
local HitCharacter=HitPart.Parent
local Humanoid=HitCharacter:FindFirstChild("Humanoid")
if HitCharacter.Name ~= Player.Name and Humanoid then

        --Checking Position in Realtime
        --local myTask=coroutine.create(function()
        --    while(true) do
        --        task.wait(0.1)
        --        print(HitCharacter.HumanoidRootPart.CFrame.Z)
        --    end

        --end)
        --coroutine.resume(myTask)
        --task.spawn(function()
        --    task.wait(6)
        --    coroutine.close(myTask)
        --end)

        local HumanoidHitAnimation = Humanoid.Animator:LoadAnimation(HitAnimation)
        task.delay(0.2,function()
            Sounds[2]:Play()
            HumanoidHitAnimation:Play()
            HumanoidHitAnimation.Stopped:Wait()
            local p=HitCharacter.Torso.CFrame
            HumanoidHitAnimation:AdjustWeight(0,0)
            HitCharacter.HumanoidRootPart.CFrame=p
        end)


        Humanoid.Health-=DamageValues[Combo+1]

        if(Humanoid.Health<=0) then
            Player:WaitForChild("leaderstats").Kills.Value+=1
        end
    else
        Hitbox.Touched:Once(Hit)
    end
end

Hitbox.Touched:Once(Hit)

Debris:AddItem(Hitbox,HitBoxCooldown)

end)

#

However my animation plays then the humanoid is teleported a few studs back then back to its correct position where it should be after its been knockback

clever fulcrumBOT
#

studio** You are now Level 1! **studio

potent tide
#

local blah = blah
#
local ReplicatedStorage=game:GetService("ReplicatedStorage")
local Sounds=ReplicatedStorage.Sounds:GetChildren()
local CombatEvent=ReplicatedStorage:WaitForChild("Combat")
local Debris=game:GetService("Debris")
local HitAnimation=ReplicatedStorage.Animations:WaitForChild("Hit")
local DamageValues={10,15,20} 
CombatEvent.OnServerEvent:Connect(function(Player,Combo)
    Sounds[1]:Play()
    local Character=Player.Character
    local HitBoxCooldown=2
    Character.Humanoid.WalkSpeed=10
    task.delay(2,function()
        Character.Humanoid.WalkSpeed=16
    end)

    local Hitbox=Instance.new("Part")
    Hitbox.Size=Vector3.new(7,7,7)
    Hitbox.Transparency=1
    Hitbox.CanCollide=false
    Hitbox.Anchored=true
    Hitbox.Parent=workspace
    Hitbox.BrickColor=BrickColor.new("Bright red")
    Hitbox.CFrame=Character.HumanoidRootPart.CFrame+Character.HumanoidRootPart.CFrame.LookVector*5
local function Hit(HitPart)
        local HitCharacter=HitPart.Parent
        local Humanoid=HitCharacter:FindFirstChild("Humanoid")
        if HitCharacter.Name ~= Player.Name and Humanoid then

 --[[Checking Position in Realtime
 local myTask=coroutine.create(function()
  while(true) do
task.wait(0.1)
print(HitCharacter.HumanoidRootPart.CFrame.Z)
 end

 end)
  coroutine.resume(myTask)
task.spawn(function()
 task.wait(6)
 coroutine.close(myTask)
  end)--]]

   local HumanoidHitAnimation = Humanoid.Animator:LoadAnimation(HitAnimation)
   task.delay(0.2,function()
   Sounds[2]:Play()
    HumanoidHitAnimation:Play()
   HumanoidHitAnimation.Stopped:Wait()
    local p=HitCharacter.Torso.CFrame
     HumanoidHitAnimation:AdjustWeight(0,0)
        HitCharacter.HumanoidRootPart.CFrame=p
            end)

 Humanoid.Health-=DamageValues[Combo+1]

 if(Humanoid.Health<=0) then
           Player:WaitForChild("leaderstats").Kills.Value+=1
 end
        else
            Hitbox.Touched:Once(Hit)
        end
    end

    Hitbox.Touched:Once(Hit)

    Debris:AddItem(Hitbox,HitBoxCooldown)
end)