Load animation returning nil

My problem is I am passing a remote event from a localscript into a serversided script so I can get the humanoid without any errors. The problem is, is when I try and load an animation into the humanoid on click it doesn’t work. Here is what I have coded.

local Clicking = script.Parent
local Clicks = Clicking.Clicks
local ClickingRem = game.ReplicatedStorage.Clicking
local Player = game.Players.LocalPlayer
local leaderstats = game.Players.LocalPlayer.leaderstats.Bucks
local Character = Player.Character
local Humanoid = Character:FindFirstChild(“Humanoid”)

Clicks.MouseButton1Click:Connect(function(hit)
	ClickingRem:FireServer(Humanoid,leaderstats)
	end)
-- Server Script
game.ReplicatedStorage.Clicking.OnServerEvent:Connect(function(plr,Humanoid,leaderstats)
leaderstats.Value = leaderstats.Value + 1
local FinalAnim = Humanoid:LoadAnimation(game.Workspace.TossingMoney)
FinalAnim:Play()

end)

Have you tried checking if some other script is removing “TossingMoney”? If not, I would advise trying this so it won’t throw the error. The downside is it might not work. But maybe that narrows our reasons why this won’t work.

if workspace:FindFirstChild("TossingMoney") then
local FinalAnim = Humanoid:LoadAnimation(game.Workspace.TossingMoney)
FinalAnim:Play()
end

Oh ok. I’ll try that. :smiley:

That did not work sorry…

Sorry for late responses here, But you can’t pass objects/models through events/function - in this case humanoid,

Basically you can get the humanoid when you have the player argument in the server script:

game.ReplicatedStorage.Clicking.OnServerEvent:Connect(function(plr,leaderstats)
	local playerModel = game.Workspace:FindFirstChild(plr.Name)
	local humanoid = playerModel.Humanoid
	
	leaderstats.Value = leaderstats.Value + 1
	local FinalAnim = humanoid:LoadAnimation(game.Workspace.TossingMoney)
	FinalAnim:Play()
end)

Thanks it worked! Thank you for letting me know for next time

1 Like