Animation not playing on player's humanoid

I want to create animations for certain interactions, like reading a book. This script would work if the humanoid were a rig (NPC) but it doesn’t work on the player. I’ve tried every single AnimationPriority but it didn’t work.

local anim = workspace.Rig.SeatedReading
workspace.Part.ProximityPrompt.Triggered:Connect(function(plr)
	local char = plr.Character or plr.CharacterAdded:Wait()
	local hum = char:WaitForChild("Humanoid")
	local animation = hum:LoadAnimation(anim)
	animation.Priority = Enum.AnimationPriority.Action
	animation.Looped = true
	animation:Play()
end)
1 Like

actually this way the animations are not loaded do this:

local anim = game.workspace.Rig.SeatedReading
if anim:IsA("Animation") then
workspace.Part.ProximityPrompt.Triggered:Connect(function(plr)
	local char = plr.Character or plr.CharacterAdded:Wait()
	local hum = char:FindFirstChildOfClass("Humanoid")
        local animator = hum:WaitForChild("Animator")
	local animation = animator:LoadAnimation(anim)
	animation.Priority = Enum.AnimationPriority.Action
	animation.Looped = true
	animation:Play()
end)
end

You should also check if the anim variable is an animation.

humanoid is obsolete for loading animations better use Animator

Just tried your code, animating from the animator doesn’t work for some reason.
Also this script is just to test if the animation itself works. In the future I’ll do it all in a loop and check for everything ofc.

local anim = workspace.Rig.SeatedReading
if anim:IsA("Animation") then
	workspace.Part.ProximityPrompt.Triggered:Connect(function(plr)
		local char = plr.Character or plr.CharacterAdded:Wait()
		local hum = char:WaitForChild("Humanoid")
		local animator = hum:WaitForChild("Animator")
		local animation = animator:LoadAnimation(anim)
		animation.Priority = Enum.AnimationPriority.Action
		animation.Looped = true
		animation:Play()
		print("animating")
	end)
end

if so, try to detect the event from the server and with a remote event load the animation.

This is a server script. Should I do it from a local script? I wanted to do it from the server because I want it to be visible to others as well.

to load an animation it must be from the client I think, try it and see.

if you are one of those who want super security with your anti exploit code then in the client make it receive the remote event and then with a module script load the animation and so an exploit will not be able to change the ID of the animation.

I’m sorry, I’m a bit confused. Where do I receive and play the animation? Also what is secure about loading an animation from a module script?

so you get the triggered event on the server, you send a remote event to the client and the client detects the remote event and plays the animation, no need to load the animation in a module script do it anyway but in the client

Alright, so here’s what I did, but it still doesn’t work:

LOCAL SCRIPT

if script.Parent.Name=="StarterPlayerScripts" then
	script:Destroy() -- Deleting because there is already a script in PlayerScripts (idk why it duplicates)
end
local LoadAnimation = game.ReplicatedStorage.RemoteEvents.LoadAnimation
local plr = game.Players.LocalPlayer

LoadAnimation.OnClientEvent:Connect(function(anim)
	local char = plr.Character or plr.CharacterAdded:Wait()
	local hum = char:WaitForChild("Humanoid")
	local animator = hum:WaitForChild("Animator")
	local animation = animator:LoadAnimation(anim)
	animation.Priority = Enum.AnimationPriority.Action
	animation.Looped = true
	animation:Play()
	print("animating")
end)

SERVER SCRIPT

local LoadAnimation = game.ReplicatedStorage.RemoteEvents.LoadAnimation

workspace.Part.ProximityPrompt.Triggered:Connect(function(plr)
	LoadAnimation:FireClient(plr, workspace.Rig.SeatedReading)
end)

I don’t know but wouldn’t it be better if you referenced the animation from the server withgame.workspace.Rig.SeatedReading instead of workspace.Rig.SeatedReading
edit: print the string? verify if the value is really an Animation

game.Workspace is equal to workspace, is it not?

I am getting the animation from the client, and the rule is to not trust the client, not the server.

Even after verifying the animation, and getting it from game.Workspace as u said, it didn’t work.

SERVER

local LoadAnimation = game.ReplicatedStorage.RemoteEvents.LoadAnimation

workspace.Part.ProximityPrompt.Triggered:Connect(function(plr)
	LoadAnimation:FireClient(plr, game.Workspace.Rig.SeatedReading)
end)

LOCAL

if script.Parent.Name=="StarterPlayerScripts" then
	script:Destroy()
end
local LoadAnimation = game.ReplicatedStorage.RemoteEvents.LoadAnimation
local plr = game.Players.LocalPlayer

LoadAnimation.OnClientEvent:Connect(function(anim)
	if anim:IsA("Animation") then
		local char = plr.Character or plr.CharacterAdded:Wait()
		local hum = char:WaitForChild("Humanoid")
		local animator = hum:WaitForChild("Animator")
		local animation = animator:LoadAnimation(anim)
		animation.Priority = Enum.AnimationPriority.Action
		animation.Looped = true
		animation:Play()
		print("animating")
	end
end)

prints the print? limited characters

yes it does print it. I put it there for a reason heh

how about if you republish the animation from the animation editor set the looped to true also set the priority as action2 and copy the id after publishing it and put it in the animation instance possibly you don’t have the id set right or it’s a roblox problem try to see if it’s not. @DasKairo

I republished it but it didn’t work :confused:

Maybe I am doing something wrong?

maybe it’s because of the change of the workspace network, what if you put the animation as a child of the local script otherwise I’m sorry but I don’t know so far.

wuo what if instead of the animation coming from a remote event what if you get it with a variable from the client?

That’s what I did before. This doesn’t work btw:

workspace.Part.ProximityPrompt.Triggered:Connect(function()
	local char = plr.Character or plr.CharacterAdded:Wait()
	local hum = char:WaitForChild("Humanoid")
	local animator = hum:WaitForChild("Animator")
	local animation = animator:LoadAnimation(animation)
	animation.Priority = Enum.AnimationPriority.Action
	animation.Looped = true
	animation:Play()
	print("animating")
end)

And putting the animation as the local script’s child wouldn’t work too because the scripts get replicated into the player’s PlayerScripts.