How could I add a cooldown to this animation system that fires on tool equip?
Tool.Equipped:Connect(function()
ToolEquipAnimation:Play()
ToolEquipAnimation.Stopped:Connect(function()
ToolIdleAnimation:Play()
end)
end)
Tool.Unequipped:Connect(function()
for _, AnimationTrack in pairs(Animator:GetPlayingAnimationTracks()) do
if AnimationTrack.Name == "R15ToolIdle" or AnimationTrack.Name == "R6ToolIdle" then
AnimationTrack:Stop()
end
end
end)
Local Debounce = false
Tool.Equipped:Connect(function()
If Debounce then return end --if Debounce value is true then it cant be used so we will stop the function from running
Debounce = true --setting it to true to add a coooldown
ToolEquipAnimation:Play()
ToolEquipAnimation.Stopped:Connect(function()
Debounce = false --after the animation is done we set it to false so it doesn't stop th3 function
ToolIdleAnimation:Play()
end)
end)
--i don't think you need this part but you can keep it if you want to, wont change alot (i think)
Tool.Unequipped:Connect(function()
for _, AnimationTrack in pairs(Animator:GetPlayingAnimationTracks()) do
if AnimationTrack.Name == "R15ToolIdle" or AnimationTrack.Name == "R6ToolIdle" then
AnimationTrack:Stop()
end
end
end)
You can set the Debounce to false out of the function to avoid any bugs but it will need a wait() or a delay() and you will need the time needed for the animation to fully finish
If you dont want to to be after the animation is done then at the end of that function use wait(number) Debounce = false or use delay its pretty advanced but simple, another way is use a while loop NOT in the function and it checks if Debounce is true and after a specific time it makes it true, or you can just leave it as it is .-.
I probably should have said this. I basically want the player to have a cooldown before equipping the tool again.
Example:
When the player unequips the tool it has a cooldown until you can equip it again. I am having a massive brain moment so I am not sure how to write it out.
Okay it will be the same thing, except if the Debounce is true we will force unequip the tool using Humanoid:UnequipTools() which is a function made by roblox
local Debounce = false -- i had local capital last script, sry about that but im writing with my phone :-:
Tool.Equipped:Connect(function()
if Debounce then return end --if Debounce value is true then it cant be used so we will stop the function from running
ToolEquipAnimation:Play()
ToolEquipAnimation.Stopped:Connect(function()
ToolIdleAnimation:Play()
end)
end)
Tool.Unequipped:Connect(function()
Debounce = true
delay(1 , function() --change 1 to the delay you want, delay to not yield the whole script, it delays the things inside the function ONLY
Debounce = false
end)
for _, AnimationTrack in pairs(Animator:GetPlayingAnimationTracks()) do
if AnimationTrack.Name == "R15ToolIdle" or AnimationTrack.Name == "R6ToolIdle" then
AnimationTrack:Stop()
end
end
end)
This is the ending code, dumb mistakes ngl, you didnt reply telling me which type of script is it so this will work with both…
local Debounce = false
Tool.Equipped:Connect(function()
local Character = game.Players.LocalPlayer.Character
local Humanoid = Character:FindFirstChildWhichIsA("Humanoid")
if Debounce then Humanoid:UnequipTools() return end --if Debounce value is true then it cant be used so we will stop the function from running and unequip the tools
ToolEquipAnimation:Play()
ToolEquipAnimation.Stopped:Connect(function()
ToolIdleAnimation:Play()
end)
end)
Tool.Unequipped:Connect(function()
Debounce = true
delay(1 , function() --change 1 to the delay you want, delay to not yield the whole script, it delays the things inside the function ONLY
Debounce = false
end)
for _, AnimationTrack in pairs(Animator:GetPlayingAnimationTracks()) do
if AnimationTrack.Name == "R15ToolIdle" or AnimationTrack.Name == "R6ToolIdle" then
AnimationTrack:Stop()
end
end
end)