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

How do i make a move non- spamable?

local UIS = game:GetService('UserInputService')
local Player = game.Players.LocalPlayer
local Character = Player.Character 
local debounce = false 
local cooldown = 10 ----- what i tried but it didn't work

UIS.InputBegan:connect(function(input)
    if input.KeyCode == Enum.KeyCode.C then
        Color = (Instance.new("ColorCorrectionEffect")) 
        Color.Name = "BlackAndWhite" 
        Color.Brightness = 0 
        Color.Contrast = 0
        Color.Enabled = true 
        Color.Saturation = -1 
        Color.TintColor = Color3.fromRGB(255,255,255) 
        Color.Parent = game.Lighting 
        local Anim = Instance.new('Animation')
        Anim.AnimationId = 'rbxassetid://04575842023'
        PlayAnim = Character.Humanoid:LoadAnimation(Anim)
        PlayAnim:Play()
        wait(10)
        Color:remove()

    end
end)

PlayAnim:Stop()

World.OnClientEvent:Connect(function()
	wait(cooldown) --- sill didn't work
	debounce = false
end)

i tried to give this a cooldown and tried to give it a 10 seconds cooldown but it didn't work pls help

1 answer

✓ Accepted answer

u have to add a debounce wich i guess u attempted but not quite right

local UIS = game:GetService('UserInputService')
local Player = game.Players.LocalPlayer
local Character = Player.Character 
local debounce = false 
local cooldown = 10 ----- what i tried but it didn't work

UIS.InputBegan:connect(function(input)
    if input.KeyCode == Enum.KeyCode.C and debounce == false then -- checking if debounce == false else it wont go trough
debounce = true -- making it true so it wont go trough the if statement again
        Color = (Instance.new("ColorCorrectionEffect")) 
        Color.Name = "BlackAndWhite" 
        Color.Brightness = 0 
        Color.Contrast = 0
        Color.Enabled = true 
        Color.Saturation = -1 
        Color.TintColor = Color3.fromRGB(255,255,255) 
        Color.Parent = game.Lighting 
        local Anim = Instance.new('Animation')
        Anim.AnimationId = 'rbxassetid://04575842023'
        PlayAnim = Character.Humanoid:LoadAnimation(Anim)
        PlayAnim:Play()
        wait(10)
	debounce = false -- making it false so it will go trough again and u can use ur ability again after the 10 second wait
        Color:remove()

    end
end)

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