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)
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)
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.
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.