Why does my animation not run?

I’m trying to make an animation play when you ride your bike in my game.

I’m using this script:

game.ReplicatedStorage.BikeAni.OnClientEvent:Connect(function()
	local Animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Animation)
	Animation:Play()
end)
--I know loading it without the Animator is deprecated but the API article lacks information...

I know the event fires and is received and I get no output errors but is there a reason why it isn’t playing?

You might need to change the Animation Priority?

1 Like

Is there a way of playing animations on the server? I tried the Animator but like I said the article is very vague…

I think you can, you just have the code inverted maybe? Could we also see the Server Script?

LoadAnimation is deprecated and shouldn’t be used Humanoid | Documentation - Roblox Creator Hub

Please refer to this: Using Animations | Documentation - Roblox Creator Hub

1 Like

I used the new article but it’s explanation for running animations on the server is vague.

@Jackscarlett

This is the server script (It checks if the player owns the vehicle as well):

seat.Changed:Connect(function(plr)
	if seat.Occupant then
		if seat.Occupant.Name ~= Owner then
			local humanoid = seat.Occupant
			if humanoid then
				Player = game:GetService("Players"):GetPlayerFromCharacter(humanoid.Parent)
				Character = humanoid.Parent
				if Player then
					seat:SetNetworkOwner(Player)
					seat.Occupant.Jump = true
				end
			end
		elseif seat.Occupant.Name == Owner then
			local humanoid = seat.Occupant
			Driving = true
			local Ani = humanoid:LoadAnimation(script.Animation)
			Ani:Play()
		end
	end
end)

local Ani = humanoid:LoadAnimation(script.Animation)

Can you double check to make sure that the animation you’re trying to load is valid? You could export it as an ID, and also I think you might also need to disable the Animate script as well in your Local Event

This line of script gets no error:

--ServerSide
if seat.Occupant then
		local HumSeat = seat.Occupant
		local Char = HumSeat.Parent
		local SeatPlayer = game:GetService("Players"):GetPlayerFromCharacter(Char)
		game.ReplicatedStorage.BikeAni:FireClient(SeatPlayer)
	end

But this one doesn’t play the animation:

--ClientSide
local Players = game:GetService("Players")

local player = Players.LocalPlayer
local character = player.Character
if not character or not character.Parent then
	character = player.CharacterAdded:Wait()
end
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")

local Animation = Instance.new("Animation")
Animation.AnimationId = "rbxassetid://6190468193"

local AnimationTrack = animator:LoadAnimation(Animation)

game.ReplicatedStorage.BikeAni.OnClientEvent:Connect(function()
	AnimationTrack:Play()
end)

This is deprecated. Use Animator:LoadAnimation() instead

In the post above yours I used that in the local script and I got no errors but it did not do anything. I heard you needed to make the animator with Instance.new but I wasn’t sure. Do you know anything about that?

It also depends. Who owns the animation? Make sure that the animation is owned by you or (if this game is owned by a group) by the group.

The animation is owned by my group but was uploaded by my animator…

Cause it be possible that your Animator didn’t allow it for copying to be available for everyone?

Is the game a group game or an independently owned game by you?

The game is in the group. So it’s strange why it didn’t work especially considering I used animations that he uploaded in the group before…

Then I assume it’s an issue with your script. Try this

elseif seat.Occupant.Name == Owner then
	local humanoid = seat.Occupant
	Driving = true
    local Animator = Humanoid:FindFirstChildOfClass("Animator")
	local Ani = Animator:LoadAnimation(script.Animation)
	Ani:Play()
    print('playing')
end

By the way, can I see your Owner variable?

The owner is the string value under the vehicle. I know that part of the script runs but the animation doesn’t play