Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

how do I prevent the player from spamming the countdown?

Asked by 4 years ago
Edited 4 years ago

Sorry for the bad English ,it's not my native language.

I did a dash script that had a cooldown of 3 seconds.To show the player the cooldown i did a GUI TextLabel.To do the countdown script,I made that it only activates if it meets the same requirements as the dash script. That's the script.

local seconds = script.Parent.Parent.time
local UIS = game:GetService("UserInputService")
local localPlayer = game.Players.LocalPlayer
repeat wait() until localPlayer.Character ~= nil
local character= localPlayer.Character
local humanoid= character:WaitForChild("Humanoid")
UIS.InputBegan:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.E and seconds.Value == 3 and humanoid:GetState()== Enum.HumanoidStateType.Freefall then
        script.Parent.Text = seconds.Value
        for i=1,seconds.Value do
            wait(1)
            seconds.Value = seconds.Value-1
            script.Parent.Text = seconds.Value
            end
    elseif seconds.Value == 0 then
        seconds.Value = 3
        script.Parent.Text = 'E'
    end
end)

The problem is that if the player spams the E key when the seconds.Value is 3 and Freefalling the player will activate the counter several times what will cause the countdown going to negative numbers and never reseting.

0
nevermind i just used a Debounce system. extroias 16 — 4y

Answer this question