Animation will not play

I made a little dumbbell and when you click it is supposed to play an animation, when I click the animation only plays after you unequipped the tool. Never had this problem before so I have no idea whats wrong. Help me please.

Local script (Inside the tool)


local Handle = script.Parent.Handle
local Tool = script.Parent
local rep = game:GetService("ReplicatedStorage")
local Event = rep.WeightUsed

Tool.Activated:Connect(function(Player)
	
	Event:FireServer(Player)
end)

Server script (Inside of server script service)

local Players = game.Players
local rep = game:GetService("ReplicatedStorage")
local Event = rep.WeightUsed
local weight5Click = game.Workspace["5poundWeights"].ClickDetector
local Curl = script.Curl

Players.PlayerAdded:Connect(function(player)
	local Folder = Instance.new("Folder")
	local IntValue = Instance.new("IntValue")
	Folder.Name = "Strength"
	IntValue.Name = "StrengthStats"
	Folder.Parent = player
	IntValue.Parent =  Folder
end)

weight5Click.MouseClick:Connect(function(Player)
	local DumbBell = "FivelbTool"
	if not Player.Backpack:FindFirstChild(DumbBell) then
	
	local Weight5 = rep.FivelbTool
	local NewTool = Weight5:Clone()
	
	NewTool.Parent = Player.Backpack
    end
end)

Event.OnServerEvent:Connect(function(Player)
	local Folder = Player:WaitForChild("Strength")
	local IntValue = Folder.StrengthStats
	local PlrGui = Player.PlayerGui
	local StrengthText = PlrGui.OtherStats.MainFrame.StrengthNum
	local Humanoid = Player.Character:WaitForChild("Humanoid")
	--play the curl animation
	local Animation = Humanoid:LoadAnimation(Curl)
	
	Animation:Play()
	
	IntValue.Value = IntValue.Value + 1
	StrengthText.Text = IntValue.Value
	
end)
1 Like

I am not entirely sure why your animation is not working since it looks like your code is all correct. I would recommend however playing your animation client side since it will automatically replicate to server side and is generally regarded as the appropriate way to load animations with it being much faster. Maybe doing this will fix your issue? Sorry thats the best advice I can give you.

When firing an event from the local client to the server using “OnServerEvent”, the first parameter will always be “player”. I noticed you used “Player” with a capital as the first parameter. I’m not sure if this is what’s causing the issue, but try this instead and let me know if it works or not:

Local Script:

local Handle = script.Parent.Handle
local Tool = script.Parent
local rep = game:GetService("ReplicatedStorage")
local Event = rep.WeightUsed

Tool.Activated:Connect(function()
	Event:FireServer()
end)

Server Script:

local Players = game.Players
local rep = game:GetService("ReplicatedStorage")
local Event = rep.WeightUsed
local weight5Click = game.Workspace["5poundWeights"].ClickDetector
local Curl = script.Curl

Players.PlayerAdded:Connect(function(player)
	local Folder = Instance.new("Folder")
	local IntValue = Instance.new("IntValue")
	Folder.Name = "Strength"
	IntValue.Name = "StrengthStats"
	Folder.Parent = player
	IntValue.Parent =  Folder
end)

weight5Click.MouseClick:Connect(function(Player)
	local DumbBell = "FivelbTool"
	if not Player.Backpack:FindFirstChild(DumbBell) then
	
	local Weight5 = rep.FivelbTool
	local NewTool = Weight5:Clone()
	
	NewTool.Parent = Player.Backpack
    end
end)

Event.OnServerEvent:Connect(function(player)
	local Folder = player:WaitForChild("Strength")
	local IntValue = Folder.StrengthStats
	local PlrGui = player.PlayerGui
	local StrengthText = PlrGui.OtherStats.MainFrame.StrengthNum
	local Humanoid = player.Character:WaitForChild("Humanoid")
	--play the curl animation
	local Animation = Humanoid:LoadAnimation(Curl)
	
	Animation:Play()
	
	IntValue.Value = IntValue.Value + 1
	StrengthText.Text = IntValue.Value
	
end)
1 Like

Aren’t animations already replicated even when you do them from the client? Why play it on the server when you could just play it on the client

If there is an error in your output, then i might be wrong.

if your dumbbell tool has an idle animation, make sure the idle animation isnt playing over the curling animation, try setting the curl animation’s priority to something higher than the idle’s priority.

Moved it to the client, still does not work.

local script:

local Handle = script.Parent.Handle
local Tool = script.Parent
local rep = game:GetService("ReplicatedStorage")
local Event = rep.WeightUsed
local Curl = script.Parent:WaitForChild("Curl")
local plr = game.Players.LocalPlayer

Tool.Activated:Connect(function(player)
	
	local Humanoid = plr.Character:FindFirstChild("Humanoid")
	local Animation = Humanoid:LoadAnimation(Curl)
	Animation:Play()
	
	
	Event:FireServer(player)
end)

Is there anything that comes out into the output? an error message for the animation? have you tested whether the code even runs to that line at all? is your animation priority to low? does your “Curl” animation object contain an rbxassetid that references an animation?

The priority is action 4, which I have been told is the highest, my code does run, and the animation does play, but only after you un equip the tool for some reason.

Does using Humanoid.Animator:LoadAnimation(Curl) change anything?

It does not do anything, exact same as before.

would you mind sending a picture of your explorer with the script and animation in frame