Animation problem when it plays

not sure why its doing this

local playidle,playwalk,playrun

local tool = script.Parent

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

local ItemStats = require(game:GetService("ReplicatedStorage"):WaitForChild("Assets"):WaitForChild("Modules"):WaitForChild("ItemStats"))

local equipped = false

local idleid = Instance.new("Animation")
idleid.AnimationId = "rbxassetid://"..ItemStats[tool.Name]["Animations"]["Idle"]

local walkid = Instance.new("Animation")
walkid.AnimationId = "rbxassetid://"..ItemStats[tool.Name]["Animations"]["Walk"]

local runid
if ItemStats[tool.Name]["Animations"]["Run"] then
	runid = Instance.new("Animation")
	runid.AnimationId = "rbxassetid://"..ItemStats[tool.Name]["Animations"]["Run"]
end

tool.Equipped:Connect(function()
	equipped = true
	
	game:GetService("RunService").Stepped:Wait()
	
	if not playidle then
		playidle = hum:LoadAnimation(idleid)
		playidle.Priority = Enum.AnimationPriority.Action
	end

	if not playwalk then
		playwalk = hum:LoadAnimation(walkid)
		playwalk.Priority = Enum.AnimationPriority.Movement
	end
	
	if runid and not playrun then
		playrun = hum:LoadAnimation(runid)
		playrun.Priority = Enum.AnimationPriority.Action2
	end
	
	task.spawn(function()
		game:GetService("RunService").RenderStepped:Connect(function()
			if equipped == true then
				if hum.MoveDirection.Magnitude > 0 then
					if playidle.IsPlaying then
						playidle:Stop()
					end
					if not playwalk.IsPlaying then
						playwalk:Play()
					end
					
					if hum.WalkSpeed > 14 and playrun then
						playwalk:Stop()
						if not playrun.IsPlaying then
							playrun:Play()	
						end
					end
					
					if hum.WalkSpeed <= 14 then
						if not playwalk.IsPlaying then
							playwalk:Play()
						end
						if playrun and playrun.IsPlaying then
							playrun:Stop()
						end
					end
				else
					if not playidle.IsPlaying then
						playidle:Play()
					end
					if playwalk.IsPlaying then
						playwalk:Stop()
					end
					if playrun and playrun.IsPlaying then
						playrun:Stop()
					end
				end
			end
		end)
	end)
end)

tool.Unequipped:Connect(function()
	equipped = false
	
	if playwalk.IsPlaying then
		playwalk:Stop()
	end
	
	if playidle.IsPlaying then
		playidle:Stop()
	end
	
	if runid and playrun.IsPlaying then
		playrun:Stop()
	end
end)

I don’t…exactly get the issue. You weren’t very descriptive with your problem, and the information provided by the video doesn’t really define it either. I’m guessing the script is stopping your running animation for some reason? If that is the issue, then the script provided below does not corelate with the issue in the video, as it does not change walkspeed. Please update me with more information on your issue.

1 Like

well the issue is quite obvious, but when the player stops running, the arm holding the sword glitches for a split second

1 Like