Animation not playing for running script?

I have a running script on the client and it seems when I press the shift button/keybind to active running while holding it down it does not play. I am so confused to why it does not play as no errors show up aswell as I have used the script previously for another projected and it works there perfectly.

local UserInputService = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")
local ContextActionService = game:GetService("ContextActionService")

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local animateScript = script.Parent:WaitForChild("Animate")
local runAnimation = humanoid:LoadAnimation(animateScript:WaitForChild("run").Running)
local playerStuff = script.Parent:WaitForChild("PlayerStuff")
local isRunningValue = playerStuff:WaitForChild("Running")

local camera = workspace.CurrentCamera
local fovRunTween = TweenService:Create(camera, TweenInfo.new(0.5), {FieldOfView = 75})
local fovWalkTween = TweenService:Create(camera, TweenInfo.new(0.5), {FieldOfView = 70})

local isMoving = false
local isSprinting = false

humanoid.Running:Connect(function(speed)
	if speed == 0 and isMoving and isSprinting then
		isMoving = false
		isRunningValue.Value = false
		runAnimation:Stop()
		fovWalkTween:Play()
	elseif speed > 0 and isSprinting and not isMoving then
		isMoving = true
		isRunningValue.Value = true
		fovRunTween:Play()
		runAnimation:Play()
	end
end)

ContextActionService:BindAction(
	"Sprint",
	function(actionName, inputState, inputObject)
		if inputState == Enum.UserInputState.Begin then
			isSprinting = true
			fovRunTween:Play()
			humanoid.WalkSpeed = 24
		else
			isSprinting = false
			isMoving = false
			runAnimation:Stop()
			fovWalkTween:Play()
			humanoid.WalkSpeed = 16
		end
	end,
	true,
	Enum.KeyCode.LeftShift,
	Enum.KeyCode.ButtonR1
)

ContextActionService:SetTitle("Sprint", "RUN")
2 Likes

Hey there, I don’t know why this wouldn’t error but is your place have enabled API services? Also are you testing it from studio or the roblox client?

If the game is under your account then the animation needs to be owned by you. And if it is under a group then it needs to be owned by the group. Else it will not play. I had this problem as well.

1 Like

maybe this is your problem? ( it doesn’t always throw an error )

image

Putting a wait at the top helps it load? note I do not have any other script in the game it’s a baseplate so idk why it’s doing this