Help to animation push up

And so hello everyone, I would like to add an animation when a local player clicks on a push-up tool, he does it on the spot and he can’t walk, and when he clicks on the push again, he tooldoing push-ups and he starts walking

my script

local tool = script.Parent
local IdleAnim = Instance.new("Animation")
IdleAnim.AnimationId = "rbxassetid://14493124361"
local firstTrack 
local anim = Instance.new("Animation")
anim.AnimationId = "rbxassetid://05199339571"
local track

 tool.Equipped:Connect(function()
firstTrack = script.Parent.Parent.Humanoid:LoadAnimation(IdleAnim)
firstTrack.Priority = Enum.AnimationPriority.Action
firstTrack.Looped = false
firstTrack:Play()
wait(1)
end)

tool.Activated:Connect(function()
track = script.Parent.Parent.Humanoid:LoadAnimation(anim)
track.Priority = Enum.AnimationPriority.Action
track.Looped = false
track:Play()
wait(1)
end)

 tool.Unequipped:Connect(function()
if firstTrack then
	firstTrack:Stop()
end
end)

tool.Unequipped:Connect(function()
if track then
	track:Stop()
end
end)
2 Likes

help to fix or improve the script please

load the animation by adding

local character = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.Character:Wait()

local hum = character:FindFirstChild(“Humanoid”)
if hum then
 hum:LoadAnimation(IdleAnim)
 hum:LoadAnimation(anim)
end

or you can do

local character = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.Character:Wait()

local hum = character:FindFirstChild(“Humanoid”)
local animator = hum:FindFirstChild(“Animator”)

local idleanimationinstance = (animation instance)
local animinstance = (animation instance)

local IdleAnim = animator:LoadAnimation(idleanimationinstance)
local anim = animator:LoadAnimation(animinstance)

also set the parent of the animations to the tool or humanoid

let me know which one of these works and if you get any errors because i am on mobile

actually i didnt look at your script properly but i think you just forgot to set the parent of the animations

I believe I have improved your code to what you needed, but without the animations playing I can only guess that they work correctly. Everything else should work fine though.

local tool = script.Parent
--
local IdleAnim = Instance.new("Animation")
IdleAnim.AnimationId = "rbxassetid://14493124361"
IdleAnim.Parent = script
--
local anim = Instance.new("Animation")
anim.AnimationId = "rbxassetid://05199339571"
--
IdleAnim.Parent = script
--
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local firstTrack = character.Humanoid:LoadAnimation(IdleAnim)
local track = character.Humanoid:LoadAnimation(anim)

tool.Equipped:Connect(function()
	firstTrack:Play()
	wait(1)
end)

tool.Activated:Connect(function()
	character.Humanoid.WalkSpeed = 0 --Added these as you said "he does it on the spot and he can’t walk"
	character.Humanoid.JumpHeight = 0
	track:Play()
	wait(1)
	character.Humanoid.WalkSpeed = 16
	character.Humanoid.JumpHeight = 50
end)

tool.Unequipped:Connect(function()
	if firstTrack then
		firstTrack:Stop()
	end

	if track then
		track:Stop()
		character.Humanoid.WalkSpeed = 16
		character.Humanoid.JumpHeight = 50
	end
end)

Let me know if you encounter any issues.

thank you who helped me, but I want to remove the animation idle