Why is an animation playing properly at times, and not at others?

Hey!
So recently ive been making a run script and whenever i run, the animation will randomly play properly and wont other times

Video
robloxapp-20220801-1836123.wmv (3.1 MB)

Script:
local UIS = game:GetService(‘UserInputService’)
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Cam = game.Workspace.CurrentCamera
local TweenServ = game:GetService(“TweenService”)

UIS.InputBegan:connect(function(input)–When a player has pressed LeftShift it will play the animation and it will set the normal walking speed (16) to 35.
if input.KeyCode == Enum.KeyCode.LeftShift then
local tweeningInformation = TweenInfo.new (0.3, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0)

	local partProperties ={
		FieldOfView = 80
	}
	local Tween = TweenServ:Create(Cam,tweeningInformation,partProperties)
    Tween:Play()
	Character.Humanoid.WalkSpeed = 26

local Anim = Instance.new(‘Animation’)
Anim.AnimationId = ‘rbxassetid://10437757290’
PlayAnim = Character.Humanoid:LoadAnimation(Anim)
PlayAnim:Play()
end
end)

UIS.InputEnded:connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
Character.Humanoid.WalkSpeed = 16
PlayAnim:Stop()
local tweeningInformation = TweenInfo.new (0.3, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0)

	local partProperties ={
		FieldOfView = 70
	}
	local Tween = TweenServ:Create(Cam,tweeningInformation,partProperties)
	Tween:Play()

end
end)

1 Like

Try this: Should be in StarterCharacterScripts (LocalScript)

local UIS = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Cam = game.Workspace.CurrentCamera
local TweenServ = game:GetService("TweenService")
local Anim = Instance.new("Animation")
Anim.AnimationId = "rbxassetid://10437757290"
local playinganim = nil

UIS.InputBegan:Connect(function(input) --When a player has pressed LeftShift it will play the animation and it will set the normal walking speed (16) to 35.
	if input.KeyCode == Enum.KeyCode.LeftShift then
		local tweeningInformation = TweenInfo.new (0.3, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0)

		local partProperties ={
			FieldOfView = 80
		}
		local Tween = TweenServ:Create(Cam,tweeningInformation,partProperties)
		Tween:Play()
		Character.Humanoid.WalkSpeed = 26
		local PlayAnim = Character.Humanoid:LoadAnimation(Anim)
		playinganim = PlayAnim
		if not playinganim.IsPlaying then
			playinganim:Play()
		end
	end
end)

UIS.InputEnded:connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftShift then
		Character.Humanoid.WalkSpeed = 16
		if playinganim.IsPlaying then
			playinganim:Stop()
		end
		local tweeningInformation = TweenInfo.new (0.3, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0)

		local partProperties ={
			FieldOfView = 70
		}
		local Tween = TweenServ:Create(Cam,tweeningInformation,partProperties)
		Tween:Play()
	end
end)

Thanks, it seems to work properly now

1 Like