Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to make my script taunt cooldown per inputkey?

I want to make this code script cooldown because if it not cooldown it's gonna spam pose and if I put sound in it it's gonna spam sound

local UIS = game:GetService("UserInputService")
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()


local key = 'F'

local Taunt = Instance.new("Animation")
Taunt.AnimationId = 'rbxassetid://3616396884' -- other animations 2262820217, 2262813409, 2425154387, 
local taunted = false

UIS.InputBegan:Connect(function(Input, IsTyping)
 if IsTyping then return end
 local KeyPressed = Input.KeyCode
 if KeyPressed == Enum.KeyCode[key] then
  taunted = true
  char.Humanoid.WalkSpeed = 0
  local LoadAnimation = char.Humanoid:LoadAnimation(Taunt)
  LoadAnimation:Play()
  wait(1.5)
  char.Humanoid.WalkSpeed = 16
  taunted = false
 end
end)

1 answer

✓ Accepted answer

It seems like you already almost have a debounce. Simply add if taunted then return end to the script, like this:

local UIS = game:GetService("UserInputService")
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()


local key = 'F'

local Taunt = Instance.new("Animation")
Taunt.AnimationId = 'rbxassetid://3616396884' -- other animations 2262820217, 2262813409, 2425154387, 
local taunted = false

UIS.InputBegan:Connect(function(Input, IsTyping)
 if taunted then return end
 if IsTyping then return end
 local KeyPressed = Input.KeyCode
 if KeyPressed == Enum.KeyCode[key] then
  taunted = true
  char.Humanoid.WalkSpeed = 0
  local LoadAnimation = char.Humanoid:LoadAnimation(Taunt)
  LoadAnimation:Play()
  wait(1.5)
  char.Humanoid.WalkSpeed = 16
  taunted = false
 end
end)

If my answer solved your problem please don't forget to upvote and accept it. Thanks!

1 comment

0

Thanks You ^^ Its Work!

This discussion is preserved as it was. New answers, comments, and votes are closed.