Animation stopping locally but not on the server

Ive been having this problem for an extremely long time and im completely out of ideas on how to fix it. Whenever the player unsheathes their weapon, both the run and idle animations change based off the type of weapon it is, and when the weapon is sheathed once again it’ll go back to the default animations. It works perfectly fine on the client but for some reason it doesn’t on the server.

While standing still:
What the player sees on the client:

What the server sees:

Sorry for the really low quality videos but the one on top is the player standing idle and the bottom is the player walking in place, even though they should be idle.

Script:

local plr = game.Players.LocalPlayer
local char = plr.Character
local hum = char:WaitForChild("Humanoid")

local RunTrack = script:WaitForChild("RunAnim")
local IdleTrack = script:WaitForChild("IdleAnim")

local RunAnim = hum:LoadAnimation(RunTrack)
local IdleAnim = hum:LoadAnimation(IdleTrack)

local SprintAnim = script.Parent:WaitForChild("Actions"):WaitForChild("Sprint"):WaitForChild("SprintAnim")

local function FindWings()

	-- Ignore this its just to get the players wings 
end

local function FindWeapon()

	for _,Item in pairs(char:GetChildren()) do

		if Item:GetAttribute("Type") == "Longsword" or Item:GetAttribute("Type") == "Greatsword" or Item:GetAttribute("Type") == "Spear" then

			return Item			

		end
	end
end

local function Transition(AnimID,AnimName)
	local WingType = FindWings()
	local Weapon = FindWeapon()
	for _, oldTrack in pairs(hum:GetPlayingAnimationTracks()) do
		
		if oldTrack.Name == tostring(AnimName) then -- Wait for old track to stop

			local newAnim = Instance.new("Animation")
			newAnim.AnimationId = AnimID

			local newTrack = hum:LoadAnimation(newAnim)
			newTrack.Looped = true
			newTrack:Play()  -- Start new anim

			oldTrack.Stopped:Connect(function() -- Wait for old anim to stop
				newTrack:Stop()
				
				AnimName.AnimationId = AnimID
				RunTrack = script:WaitForChild("RunAnim") -- Change run anim
				IdleTrack = script:WaitForChild("IdleAnim") -- Change idle anim

				RunAnim = hum:LoadAnimation(RunTrack) -- Reload run anim
				IdleAnim = hum:LoadAnimation(IdleTrack) -- Reload idle anim
				
			end)
		else
			
			AnimName.AnimationId = AnimID
			RunTrack = script:WaitForChild("RunAnim")
			IdleTrack = script:WaitForChild("IdleAnim")

			RunAnim = hum:LoadAnimation(RunTrack)
			IdleAnim = hum:LoadAnimation(IdleTrack)
			
		end
	end
	
end

local function StartTransition()
	
	local Sheathed = plr:GetAttribute("Sheathed")
	local WingType = FindWings()

	if Sheathed == true then

		Transition(WingAnimIndex[WingType]["Run"],RunTrack) -- Sends specific Run Animation
		Transition(WingAnimIndex[WingType]["Idle"],IdleTrack) -- Sends specific Idle Animation
		Transition(WingAnimIndex[WingType]["Sprint"],SprintAnim) -- Sends specific Sprint Animation

	else

		local Weapon = FindWeapon()
		if Weapon then

			local Type = Weapon:GetAttribute("Type")

			Transition(WingAnimIndex[WingType][Type.."Run"],RunTrack) -- Sends default Run Animation
			Transition(WingAnimIndex[WingType][Type.."Idle"],IdleTrack) -- Sends default Idle Animation
			Transition(WingAnimIndex[WingType][Type.."Sprint"],SprintAnim) -- Sends default Sprint Animation

		end

	end
	
end

plr:GetAttributeChangedSignal("Sheathed"):Connect(function()
	
	StartTransition()

end)

char.ChildAdded:Connect(function(Child)
	if Child:GetAttribute("Type") == "Longsword" or Child:GetAttribute("Type") == "Greatsword" or Child:GetAttribute("Type") == "Spear" then
		
		StartTransition()
		
	end	
end)

local Running = false

hum.Running:Connect(function(speed)
	
	if speed > 0 and not Running then
		print("Running")
		Running = true
		
		RunAnim:Play()
		for _, brokenTrack in pairs(hum:GetPlayingAnimationTracks()) do
			
			if brokenTrack.Name == "Animation" then -- Stops idle animation from playing while running

				warn("Fixing Broken Run Anim")
				brokenTrack:Stop()

			end
			
		end
	elseif speed <= 0 and Running then
		print("Idling")
		IdleAnim:Play()
		Running = false
		for _, brokenTrack in pairs(hum:GetPlayingAnimationTracks()) do
			if brokenTrack.Name == "RunAnim" then -- Stops run animation from playing while standing still
				
				warn("Fixing Broken Run Anim")
				brokenTrack:Stop()				
			end
		end
		
	end
	
end)
1 Like