Sprint Animation not implementing

I have been researching the devforums and every youtube tutorial for an hour and a half now and I haven’t gone any fix to this script:

Basically, whenever the Shift Key is pressed and state is running, a custom run animation will play but somehow it doesn’t work. Please help me (I ran out of braincells lol)

Edit: No errors show up, just to clear up some confusion

local UserInput = game:GetService("UserInputService")
local Camera = game.Workspace.Camera
local TweenService = game:GetService("TweenService")

local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Quint, Enum.EasingDirection.Out, 0, false, 0)

local ModifiedFieldOfView = 70
local CameraTweenSprinting = TweenService:Create(Camera, tweenInfo, {FieldOfView = 90})
local CameraTweenNormal = TweenService:Create(Camera, tweenInfo, {FieldOfView = 70})

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()

local remoteEvents = replicatedStorage.RemoteEvents
local Sprint = remoteEvents:WaitForChild("Sprint")

--local Anim = Instance.new("Animation", workspace)
local Animation = game.Workspace.Animation
local SprintPlay = Character:WaitForChild("Humanoid"):LoadAnimation(Animation)



UserInput.InputBegan:Connect(function(input, GDE)
	
	if input.KeyCode == Enum.KeyCode.LeftShift then
		Sprint:FireServer("Began")
		Animation:Play()
		if Camera then
			CameraTweenSprinting:Play()
		end
	end

end)

UserInput.InputEnded:Connect(function(input, GDE)

	if input.KeyCode == Enum.KeyCode.LeftShift then
		Sprint:FireServer("Ended")
		Animation:Stop()
		if Camera then
			CameraTweenNormal:Play()

		end
	end

end)

I think you have to use SprintPlay:Play() since that is the animationTrack that was loaded in the Humanoid.

1 Like

oh ye sorry, I forgot I have to replicate the script I had since it had gone trough many changes, I did that but it still didn’t work

Ok, if you add a print before playing does that get shown in the output? Basically, is the code called?

The code looks completely fine to me. Are you sure game.Workspace.Animation is the correct animation? Usually animations get loaded by id.

Camera should be workspace.CurrentCamera, instead of humanoid:LoadAnimation(), use animator:LoadAnimation(). animator is located inside of the humanoid.

Another problem is you aren’t waiting for RemoteEvents. If you’re using a script inside of a player you need to wait for pretty much everything to load before your script can work.

1 Like

Maybe your animation is set to the Core animation priority. Check that out and see if its Movement or Action.

The Code is Called since the Camera is tweened as intended and the Remote Event is fired which modifies the WalkSpeed, and yes the animation is checked and is valid

Oh ye tnx for telling me about the Camera, I also did Humanoid.Animator:LoadAnimation() but it still doesnt work yet.

About this, can you please tell me more since I dont quite understand

I asked my animator to double check if its set to Action, and yes its confirmed that its set to Action

Change

to

local Animation = game.Workspace.Animation
local AnimationTrack = Character.Humanoid.Animator:LoadAnimation(game.Workspace.Animation)

and instead of playing the animation varible like this:

instead play the AnimationTrack like this:

AnimationTrack:Play()

Sadly It still doesn’t work yet, but I do have a question, what does Changing the name of the variables have to do with this, is there any sort of functionality in Roblox? Tell me more :smile:

This might not really help solving the issue, but its better to make the code better.
Humaoid:LoadAnimation() is deprecated, rather. Use Humanoid.Animator:LoadAnimation().

1 Like

I am bad at explaining so I’mma let roblox explain: This function loads an Animation onto a Humanoid , returning an AnimationTrack that can be used for playback.

The names of the variables don’t really have to do anything with this though.

1 Like

Okay thanks for letting me know. I edited the script I put.

1 Like

You can put prints through out the script to see where it is working and where it is not if there is an error with the script. I know you said there are no errors in the output though.

1 Like

Alr somehow it works now, my studio actually crashed then when I opened the team project it works, I havent made any changes but idk why it works now. Tnx for the help tho

1 Like