Character only plays animation once?

I’m currently making a pushup tool. When you equip it, the character stops and gets into a pushup position. When you unequip, they get up. When you click it plays a pushup. But for some reason, after you activate the tool once, it won’t play the pushup animation again?

Script:

--//VARIABLES\\--
local IdleAnim = script.Idle
local PushupAnim = script.Pushup
local Player
local Character
local Humanoid
local Idle
local Pushup

db = false

--//EQUIP/UNEQUIP\\--
script.Parent.Equipped:Connect(function()
	Character = script.Parent.Parent
	Humanoid = Character:WaitForChild("Humanoid")
	Player = game.Players:WaitForChild(Character.Name)
	
	Humanoid.WalkSpeed = 0
	Humanoid.JumpPower = 0
	
	Idle = Humanoid:LoadAnimation(IdleAnim)
	Pushup = Humanoid:LoadAnimation(PushupAnim)
	
	for i, v in pairs(Humanoid:WaitForChild("Animator"):GetPlayingAnimationTracks()) do
		v:Stop()
	end
	
	Idle:Play()
end)

script.Parent.Unequipped:Connect(function()
	Humanoid.WalkSpeed = 16
	Humanoid.JumpPower = 50
	
	Idle:Stop()
end)

--//FUNCTION\\--
script.Parent.Activated:Connect(function()
	if db == false then
		Pushup:Play()
		task.wait(.5)
		db = true
	end
end)
1 Like
local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character
local Humanoid:Humanoid? = Character:FindFirstChildOfClass("Humanoid") or Character:WaitForChild("Humanoid", 25)
local Animator = Humanoid:FindFirstChildOfClass("Animator")
local IdleAnim = script:WaitForChild("Idle")
local PushUpAnim = script:WaitForChild("Pushup")
local Idle:AnimationTrack? = Animator:LoadAnimation(IdleAnim)
local CD = false
local Pushup:AnimationTrack? = Animator:LoadAnimation(PushUpAnim)
local Tool:Tool? = script.Parent
Tool.Equipped:Connect(function()
	for _,v in Animator:GetPlayingAnimationTracks() do
		v:Stop()
	end
	Humanoid.WalkSpeed = 0
	Humanoid.JumpPower = 0
	Idle:Play()
end)
Tool.Unequipped:Connect(function()
	Humanoid.WalkSpeed = 16
	Humanoid.JumpPower = 50
	Idle:Stop()
end)
Tool.Activated:Connect(function()
	if not CD then
		CD = true
		Pushup:Play()
		task.wait(0.5)
		CD = false
	end
end)

If you’re looking for a server script lemme know.

1 Like

Thanks, but yes; it is a server script.

1 Like

Ah alright, i’ll make one rq hold on

1 Like

Alright here is a server script one.

local Character = script.Parent.Parent
local Player = game:GetService("Players"):GetPlayerFromCharacter(Character)
local Humanoid:Humanoid? = Character:FindFirstChildOfClass("Humanoid") or Character:WaitForChild("Humanoid", 25)
local Animator = Humanoid:FindFirstChildOfClass("Animator")
local IdleAnim = script:WaitForChild("Idle")
local PushUpAnim = script:WaitForChild("Pushup")
local Idle:AnimationTrack? = Animator:LoadAnimation(IdleAnim)
local CD = false
local Pushup:AnimationTrack? = Animator:LoadAnimation(PushUpAnim)
local Tool:Tool? = script.Parent
Tool.Equipped:Connect(function()
	for _,v in Animator:GetPlayingAnimationTracks() do
		v:Stop()
	end
	Humanoid.WalkSpeed = 0
	Humanoid.JumpPower = 0
	Idle:Play()
end)
Tool.Unequipped:Connect(function()
	Humanoid.WalkSpeed = 16
	Humanoid.JumpPower = 50
	Idle:Stop()
end)
Tool.Activated:Connect(function()
	if not CD then
		CD = true
		Pushup:Play()
		task.wait(0.5)
		CD = false
	end
end)

Althought it’s pretty recommended to use the first one if youjust wanna play animations.

1 Like

as far as I can understand it doesn’t play the animation again because in the activated function you check if db is equal to false and after .5 seconds you set it to true, but you never set it to false again so the if statement gets skipped.

1 Like

You’re right, but I think that @weakroblox35’s works better than mine. Thanks to you both!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.