[Pls Help!] Animation in Running Script No working!

Hello developers, today I wanted to add an animation to my running script.
Script [Before] :

while not game:GetService('UserInputService').KeyboardEnabled and not game:GetService('UserInputService').TouchEnabled and not game:GetService('UserInputService').GamepadEnabled do
	wait()
end
while not game:GetService('Players').LocalPlayer do
	wait()
end
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local function repeatwait(object,waiting)
	repeat game:GetService("RunService").RenderStepped:wait() until object:FindFirstChild(waiting)
	return object[waiting]
end
local function WaitForCharacterLoad(char)
	repeatwait(char,"Head")
	repeatwait(char,"UpperTorso")
	repeatwait(char,"LowerTorso")
	repeatwait(char,"LeftLowerLeg")
	repeatwait(char,"RightLowerLeg")
	repeatwait(char,"LeftUpperLeg")
	repeatwait(char,"RightUpperLeg")
	repeatwait(char,"LeftUpperArm")
	repeatwait(char,"RightUpperArm")
	repeatwait(char,"LeftLowerArm")
	repeatwait(char,"RightLowerArm")
	repeatwait(char,"LeftHand")
	repeatwait(char,"RightHand")
	repeatwait(char,"LeftFoot")
	repeatwait(char,"RightFoot")
	repeatwait(char,"Humanoid")
	repeatwait(char,"HumanoidRootPart")
	return nil
end


player.CharacterAdded:connect(function(char)
	WaitForCharacterLoad(char)
	local pushed = false
	local Settings = UserSettings()
	local GameSettings = Settings.GameSettings
	local event1 = mouse.KeyDown:connect(function(key)

		if key == "0"  and not char:FindFirstChild("Debounce") and not char:FindFirstChild("Hitted") then
			pushed = true
			game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 40

			GameSettings.RotationType = Enum.RotationType.MovementRelative

			for i = 1,5 do
				game.Workspace.CurrentCamera.FieldOfView = (70+(i*2))
				wait()
			end
		end
	end)

	local event2 = mouse.KeyUp:connect(function(key)
		if key == "0" and pushed and game.Players.LocalPlayer.Character.Humanoid.WalkSpeed == 40 then
			pushed = false
			game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16

			GameSettings.RotationType = Enum.RotationType.CameraRelative 
			for i = 1,5 do
				game.Workspace.CurrentCamera.FieldOfView = (80-(i*2))
				wait()
			end
		end
	end)
	char.Humanoid.Died:connect(function()
		event1:disconnect()
		event2:disconnect()
	end)
end)

Script [Current] No working

local Player = game.Players.LocalPlayer
local Character = Player.Character
local hum = Character.Humanoid

local RunAnim = script.RunAnim
local RunTrack = hum:LoadAnimation(RunAnim)


while not game:GetService('UserInputService').KeyboardEnabled and not game:GetService('UserInputService').TouchEnabled and not game:GetService('UserInputService').GamepadEnabled do
	wait()
end
while not game:GetService('Players').LocalPlayer do
	wait()
end
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local function repeatwait(object,waiting)
	repeat game:GetService("RunService").RenderStepped:wait() until object:FindFirstChild(waiting)
	return object[waiting]
end
local function WaitForCharacterLoad(char)
	repeatwait(char,"Head")
	repeatwait(char,"UpperTorso")
	repeatwait(char,"LowerTorso")
	repeatwait(char,"LeftLowerLeg")
	repeatwait(char,"RightLowerLeg")
	repeatwait(char,"LeftUpperLeg")
	repeatwait(char,"RightUpperLeg")
	repeatwait(char,"LeftUpperArm")
	repeatwait(char,"RightUpperArm")
	repeatwait(char,"LeftLowerArm")
	repeatwait(char,"RightLowerArm")
	repeatwait(char,"LeftHand")
	repeatwait(char,"RightHand")
	repeatwait(char,"LeftFoot")
	repeatwait(char,"RightFoot")
	repeatwait(char,"Humanoid")
	repeatwait(char,"HumanoidRootPart")
	return nil
end




player.CharacterAdded:connect(function(char)
	WaitForCharacterLoad(char)
	local pushed = false
	local Settings = UserSettings()
	local GameSettings = Settings.GameSettings
	local event1 = mouse.KeyDown:connect(function(key)

		if key == "0"  and not char:FindFirstChild("Debounce") and not char:FindFirstChild("Hitted") then
			pushed = true
			game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 40

			GameSettings.RotationType = Enum.RotationType.MovementRelative

			for i = 1,5 do
				game.Workspace.CurrentCamera.FieldOfView = (70+(i*2))
				RunTrack:Play()
				wait()
			end
		end
	end)

	local event2 = mouse.KeyUp:connect(function(key)
		if key == "0" and pushed and game.Players.LocalPlayer.Character.Humanoid.WalkSpeed == 40 then
			pushed = false
			game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16

			GameSettings.RotationType = Enum.RotationType.CameraRelative 
			for i = 1,5 do
				game.Workspace.CurrentCamera.FieldOfView = (80-(i*2))
				RunTrack:Stop()
				wait()
			end
		end
	end)
	char.Humanoid.Died:connect(function()
		event1:disconnect()
		event2:disconnect()
	end)
end)

If anyone knows the error please tell me, when I hit play the entire run script bugs :frowning:

2 Likes

Humanoid:LoadAnimation() is deprecated. There’s something called an Animator under the Humanoid instance, use that and use Animator:LoadAnimation() on it.

It doesn’t work for me :confused:

Did you just copy what I gave? Please reread my solution.


--RUNNING SCRIPT--
-------------------------------
local Player = game.Players.LocalPlayer
local Character = Player.Character
local hum = Character.Humanoid

local RunAnim = script.RunAnim
local RunTrack = hum.Animator:LoadAnimation(RunAnim)


while not game:GetService('UserInputService').KeyboardEnabled and not game:GetService('UserInputService').TouchEnabled and not game:GetService('UserInputService').GamepadEnabled do
	wait()
end
while not game:GetService('Players').LocalPlayer do
	wait()
end
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local function repeatwait(object,waiting)
	repeat game:GetService("RunService").RenderStepped:wait() until object:FindFirstChild(waiting)
	return object[waiting]
end
local function WaitForCharacterLoad(char)
	repeatwait(char,"Head")
	repeatwait(char,"UpperTorso")
	repeatwait(char,"LowerTorso")
	repeatwait(char,"LeftLowerLeg")
	repeatwait(char,"RightLowerLeg")
	repeatwait(char,"LeftUpperLeg")
	repeatwait(char,"RightUpperLeg")
	repeatwait(char,"LeftUpperArm")
	repeatwait(char,"RightUpperArm")
	repeatwait(char,"LeftLowerArm")
	repeatwait(char,"RightLowerArm")
	repeatwait(char,"LeftHand")
	repeatwait(char,"RightHand")
	repeatwait(char,"LeftFoot")
	repeatwait(char,"RightFoot")
	repeatwait(char,"Humanoid")
	repeatwait(char,"HumanoidRootPart")
	return nil
end




player.CharacterAdded:connect(function(char)
	WaitForCharacterLoad(char)
	local pushed = false
	local Settings = UserSettings()
	local GameSettings = Settings.GameSettings
	local event1 = mouse.KeyDown:connect(function(key)

		if key == "0"  and not char:FindFirstChild("Debounce") and not char:FindFirstChild("Hitted") then
			pushed = true
			game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 40

			GameSettings.RotationType = Enum.RotationType.MovementRelative

			for i = 1,5 do
				game.Workspace.CurrentCamera.FieldOfView = (70+(i*2))
				RunTrack:Play()
				wait()
			end
		end
	end)

	local event2 = mouse.KeyUp:connect(function(key)
		if key == "0" and pushed and game.Players.LocalPlayer.Character.Humanoid.WalkSpeed == 40 then
			pushed = false
			game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16

			GameSettings.RotationType = Enum.RotationType.CameraRelative 
			for i = 1,5 do
				game.Workspace.CurrentCamera.FieldOfView = (80-(i*2))
				RunTrack:Stop()
				wait()
			end
		end
	end)
	char.Humanoid.Died:connect(function()
		event1:disconnect()
		event2:disconnect()
	end)
end)

I already did it but it doesn’t work for me, I’m not sure, maybe I did something wrong. sorry I’m using translator