Im trying to make a idle stance for the player IF their holding a katana weapon

Hello! Im trying to make it so if a player equips the katana then what will happen is if their standing then they will have a standing animation I made looped for how ever long they stand

The Problem is for some reason when I walk then for some reason the animation keeps going and It looks strange, also for some reason it doesnt loop at all.

How do I make it so it has a walking animation whenever it walks? I already made on but Im still slowly learning how to animate so idk how to make it so when I walk WITH the katana then It starts the walking animation.

Script

local remote = script.Parent:WaitForChild("Katana")

remote.OnServerEvent:Connect(function(Player, Value)
	local character = workspace:WaitForChild(Player.Name)
	if Value == "Equipped" then
		print("A Item Has Been Equipped!")
		
		local lookForAnimation = character:FindFirstChild("KatanaEquippedAnimation")
		if lookForAnimation then
			lookForAnimation:Destroy()
		end
		
		local animation = Instance.new("Animation", character)
		animation.Name = "KatanaEquippedAnimationV2"
		animation.AnimationId = "rbxassetid://6581749713"
		local loader = character:WaitForChild("Humanoid"):LoadAnimation(animation)
		loader:Loop()
		
	elseif Value == "Attack" then
		print("A Player Has Attacked!")
	end
end)

There are two ways I can think of right now to let walk animation play.

  1. Set appropriate animation priority.

When multiple animations play at the same time, the one with higher priority level overwrites the less prior one. We know 4 priority levels (lowest to highest): core, idle, movement and action. Set your animation priority to lower level.

  1. Stopping the animation

You can simply stop animation once player starts moving around. Using Play() and Stop() methods, you can play animation at correct times.

What can be improved in your script?

Firstly, humanoid:LoadAnimation() is deprecated in favour of animator:LoadAnimation(). Animator shares very similar functions, but is encouraged to be used in newer work for the reasons explained in the following article: Deprecating LoadAnimation on Humanoid and AnimationController

Secondly, don’t load animations server-side. Animations loaded from local script do replicate and result in similar outcomes, while not burdening the server with unnecessary processes.

Write the same code for local script.

If you decide to choose the second option, perhaps consider using

humanoid.Running:Connect(function(speed)
    if (speed > 0 and animation.IsPlaying) then
        animation:Stop()
    elseif (speed <= 0 and not animation.IsPlaying) then
        animation:Play()
end)

Each time player starts running stop playing the animation, under the condition that it is still playing, and vice versa.

EDIT I’d personally go for the first option almost without doubt. I also didn’t get the chance to test anything.

EDIT (2) @StarJ3M

The whole animation part belongs in a local script in StarterCharacter scripts. The humanoid.Running event was just an idea, but you’ll have to figure out what suits your script best. I may have done a typo as well, because I’m writing on a phone.

3 Likes

For option 2 where would I put that part?