How can i make a debounce for this script?
local UserInputService = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Character = workspace:WaitForChild(Player.Name)
local Humanoid = Character:WaitForChild("Humanoid")
local CombatEnabled = false
local CombatAnim = script:WaitForChild("CombatAnim")
local animTable = {"rbxassetid://5021409784";"rbxassetid://5021418974";"rbxassetid://5021422938";"rbxassetid://5021425832"}
UserInputService.InputBegan:Connect(function(Input,IsTyping)
if not IsTyping then
if Input.KeyCode == Enum.KeyCode.E then
CombatEnabled = true
print("Combat Enabled!")
spawn(function()
while CombatEnabled == true do
local randomAnimation = math.random(1, #animTable)
local randomAnim_Value = animTable[randomAnimation]
CombatAnim.AnimationId = tostring(randomAnim_Value)
local CombatAnimLoader = Humanoid:LoadAnimation(CombatAnim)
-- game.ReplicatedStorage.Combat:FireServer("CombatEnabled",animTable)
CombatAnimLoader:Play()
print(randomAnim_Value)
wait(CombatAnimLoader.Length + 0.2)
if CombatEnabled == false then
print("Combat Disabled!")
break
end
end
end)
end
end
end)
UserInputService.InputEnded:Connect(function(Input, IsTyping)
if not IsTyping then
if Input.KeyCode == Enum.KeyCode.E then
CombatEnabled = false
end
end
end)
