Animation won't play

When I click with a tool equipped I want an animation to play but it will not work.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage.Remotes:WaitForChild("Basic")

remoteEvent.OnServerEvent:Connect(function(player)
	print(player.Character.Name)
	local character = player.Character
	local humanoid = character:FindFirstChild("Humanoid")
	local animation = Instance.new("Animation")
	animation.AnimationId = "rbxassetid://17397338573"
	
	local animationTrack = humanoid:LoadAnimation(animation)
	animationTrack:Play()
end)
2 Likes

Try to use humanoid.Animator:LoadAnimation instead. Just directly using the humanoid is deprecated, and it might be why your code doesn’t work.

4 Likes

I get an error saying argument 1 missing or nil on that line now. Might I need to add something?

1 Like
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage.Remotes:WaitForChild("Basic")

remoteEvent.OnServerEvent:Connect(function(player)
	print(player.Character.Name)
	local character = player.Character
	local humanoid = character:FindFirstChild("Humanoid") or player.CharacterAdded:Wait()
	local animation = Instance.new("Animation")
	animation.AnimationId = "rbxassetid://17397338573"
	
 if humanoid then
	local animationTrack = humanoid:LoadAnimation(animation)
	animationTrack:Play()
    end
end)
3 Likes

This causes the same effect I already where I get no errors but the animation does not play/

What does it print? Is it a local script or server script?

1 Like

It prints the player name. It is in a server script and runs after a local script activates a server event.

Can you send us the code in the local script?

2 Likes

Sorry Correction module script but it is

local module = {}
local replicatedStorage = game:GetService("ReplicatedStorage")

function module.Lift()
	
	replicatedStorage.Remotes.Lift:FireServer()
	replicatedStorage.Remotes.Basic:FireServer()
	
end

return module

the local script is

local module = require(script.Parent:WaitForChild("ModuleScript"))
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

script.Parent.Activated:Connect(function()
	module.Lift()
end)

1 Like

Just curious, why do you have to fire the remote events in a module? Can’t you just fire them directly in the local script?

2 Likes

I honestly can’t remember. I started this a long time ago and just came back to it.

1 Like

Try firing the remote events like this (in the LocalScript). Since your project was created a while ago (if that was what you said), some things may break overtime.

local replicatedStorage = game:GetService("ReplicatedStorage")

script.Parent.Activated:Connect(function()
	replicatedStorage.Remotes.Lift:FireServer()
	replicatedStorage.Remotes.Basic:FireServer()
end)
1 Like

It is better to fire it directly on the local script. Try to do that and tell us the result.

1 Like

Still does not play the animation but this does make much more sense to do.

1 Like

You could also try:

local replicatedStorage = game:GetService("ReplicatedStorage")

local parent = script.Parent

local Basic, Lift = replicatedStorage.Remotes:WaitForChild("Basic"), replicatedStorage.Remotes:WaitForChild("Lift")

local function FireEvents()
    Lift:FireServer()
    Basic:FireServer()
end

parent.Activated:Connect(FireEvents)
1 Like

We will check the problem here. try printing animationTrack.

1 Like

Try making the animation asset and use it manually instead of creating one in a script. It seems more logical if you’re playing the same animation.

1 Like

New server script.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage.Remotes:WaitForChild("Basic")

remoteEvent.OnServerEvent:Connect(function(player)
	print(player.Character.Name)
	local character = player.Character
	local humanoid = character:FindFirstChild("Humanoid")
	local animation = replicatedStorage.Animations.Animation
	
	local animationTrack = humanoid.Animator:LoadAnimation()
	animationTrack:Play()
end)
1 Like

Still does not work. Line 9 says argument 1 missing or nil

1 Like

-is animation deleted or smth?
-check if there is a humanoid part, if there is not add one

1 Like