Help with anchoring humanoid when attacking

How can i add to this script so that when im playing an animation (attack animation with sword) it anchors the humanoid? I don’t want players to be able to run and swing the sword at the same time.

wait(3)
Player = game.Players.LocalPlayer.Character
Animation1 = Player.Humanoid:LoadAnimation(script.Slices)
Animation2 = Player.Humanoid:LoadAnimation(script.Spin)
Animation3 = Player.Humanoid:LoadAnimation(script.BackFlipStab)
Animation4 = Player.Humanoid:LoadAnimation(script.DownSlice)
CanFly = true

script.Parent.Parent.Activated:connect(function()
	local Fly = math.random(1,5)
	 if Fly == 1 and CanFly == true then
		Animation1:Play()
		CanFly = false
		wait(0.5)
		CanFly = true
		
		else if Fly == 2 and CanFly == true then
		Animation2:Play()
		CanFly = false
		wait(0.5)
		CanFly = true
		
		 else if Fly == 3 and CanFly == true then
		Animation3:Play()
		CanFly = false
		wait(0.5)
		CanFly = true
		
		else if Fly == 4 and CanFly == true then
		Animation4:Play()
		CanFly = false
		wait(0.5)
		CanFly = true
		
		   end
		end
		end
	    end
	    end)
1 Like

im not sure about anchoring the player but you could set jump power and speed to 0, also i would use task.Wait(0.5) its just all around better

1 Like

Use something like:

task.wait(3)

local Player = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait()
local Character = Player.Character or Player.CharacterAdded:Wait()

local Animation1 = Player.Humanoid:LoadAnimation(script.Slices)
local Animation2 = Player.Humanoid:LoadAnimation(script.Spin)
local Animation3 = Player.Humanoid:LoadAnimation(script.BackFlipStab)
local Animation4 = Player.Humanoid:LoadAnimation(script.DownSlice)
local CanFly = true

script.Parent.Parent.Activated:connect(function()
	local Fly = math.random(1,5)
	 if Fly == 1 and CanFly == true then
		Animation1:Play()
		CanFly = false
        Character.HumanoidRootPart = true
		task.wait(0.5)
		CanFly = true
		Character.HumanoidRootPart = false
		else if Fly == 2 and CanFly == true then
		Animation2:Play()
        Character.HumanoidRootPart = true
		CanFly = false
		task.wait(0.5)
		CanFly = true
		Character.HumanoidRootPart = false
		 else if Fly == 3 and CanFly == true then
		Animation3:Play()
		CanFly = false
        Character.HumanoidRootPart = true
		task.wait(0.5)
		CanFly = true
        Character.HumanoidRootPart = false
		
		else if Fly == 4 and CanFly == true then
		Animation4:Play()
		CanFly = false
        Character.HumanoidRootPart = true
		task.wait(0.5)
		CanFly = true
		Character.HumanoidRootPart = false
		   end
		end
		end
	    end
	    end)

If you want to anchor the player just use:

Character.HumanoidRootPart.Anchored = false OR true

2 Likes

I entered the script you provided but now my attack animations wont play

1 Like

It better to do so. If you Anchor all the other Child in teh player(Head,Torso,ETC),it would be mess if you want to unanchor it back since HumanoidRootPart need to be always Unachored.

1 Like

do:

Humanoid.WalksSpeed = 0

to freeze the player
after that do

Humanoid.WalkSpeed = 16

to make the player be able to move.

2 Likes

Simply just do :
Player.Character.HumanoidRootPart.Anchored = true

1 Like

then his animations wont work. He can use the method I said above to freeze the player without stopping his animations

This will make the player freeze.
Freeze then and will stop Animation. :frowning:

wait…so anchoring will or will not allow my animations to play?

1 Like

I’m not sure, I do that all the time, and it works fine for me.

do i just replace

Character.HumanoidRootPart = true

with humanoid.walkspeed?

-- idk what that wait is but use task.Wait if your going to use wait
local player = game:GetService("Players").LocalPlayer
local Character = Player.Character
local Humanoid = Character.Humanoid



local animations = {
Animation1 = Player.Humanoid:LoadAnimation(script.Slices),
Animation2 = Player.Humanoid:LoadAnimation(script.Spin),
Animation3 = Player.Humanoid:LoadAnimation(script.BackFlipStab),
Animation4 = Player.Humanoid:LoadAnimation(script.DownSlice)
}
local canFly = true
local function giveAnimation()
      local Fly = math.Random(1,5)
      if canFly then
         local animation = animations[fly]
         canFly = false
         animation:Play()
         humanoid.Walkspeed = 0 
         humanoid.JumpPower= 0 
         task.Wait(0.5)
         humanoid.Walkspeed = 16 -- or whatever the orginal values are
         humanoid.JumpPower= 50
         canFly = true
    end
end
script.Parent.Parent.Activated:connect(giveAnimation)





1 Like

yes you do. It’ll make the animation still work while freezing the player.

1 Like

Hmm…Interesting.
I tried to use teh code with Tool animation and it no work.
Maybe I will be more carefull next time.

The animations wont play with this code for some reason. The script is inside the handle so idk if that is causing anything.

I tried it but with no luck…for some reason the animations just wont play.

yeah im having trouble getting the animations to play to play.

1 Like

there is a bug in the script rn it is

local animations = {
Animation1 = Player.Humanoid:LoadAnimation(script.Slices),
Animation2 = Player.Humanoid:LoadAnimation(script.Spin),
Animation3 = Player.Humanoid:LoadAnimation(script.BackFlipStab),
Animation4 = Player.Humanoid:LoadAnimation(script.DownSlice)
}
it should be 
local animations = {
Player.Humanoid:LoadAnimation(script.Slices),
Player.Humanoid:LoadAnimation(script.Spin),
Player.Humanoid:LoadAnimation(script.BackFlipStab),
Player.Humanoid:LoadAnimation(script.DownSlice)
}

along with that it should be math.random(1,4)