I made a function in a module script that plays animations, specifically attack animations. It also slows the player down when the animation is playing. And with attack animations, comes animation cool downs, or debounce. Here is the function in the module script:
local AttackAnimationModule = {}
AttackAnimationModule.PlayAttack = function(AnimationTrack)
if AttackDebounce == true then return end --AttackDebounce is already defined in the script that uses the module script function
AnimationTrack.Looped = false
AnimationTrack:Play()
AttackDebounce = true --Turn on cooldown
Humanoid.WalkSpeed = 3 --Slow down player
wait(1) --The animation length
Humanoid.WalkSpeed = 16
AttackDebounce = false --Turn off cooldown
end
return AttackAnimationModule
And here is the script that uses the function (LocalScript):
local UIS = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
repeat wait() until Player.Character --Load character
repeat wait() until Player.Character.Humanoid --Load humanoid
local Humanoid = Player.Character.Humanoid
local Attack = game.ReplicatedStorage.Attack
local AttackTrack = Humanoid:LoadAnimation(Attack)
local AttackAnimationModule = require(game.ReplicatedStorage.AttackAnimations)
local AttackDebounce = false
UIS.InputBegan:Connect(function(Input)
if input.KeyCode == Enum.KeyCode.E then
AttackAnimationModule.PlayAttack(AttackTrack)
end
end)
When I run both scripts, the animations, and walkspeed work completely fine. But the debounce doesn't work. Any solutions?

2 comments
Put your debounce in the LOCAL script, not in the server script. Also, use GPE (Game Processed Event) to iron out CoreGui events.
I edited the answer.