Hey guys, i was wondering how could i make a cooldown mechanic for a gui i made.
the attacks are fired by remote events and in the main local script i have all of the cooldowns values.
this is the gui
this is the local script
local UserInputService = game:GetService("UserInputService")
local debounce = false
local debounce2 = false
local debounce3 = false
local debounce4 = false
local cooldown = 0.25
local equipped = false
local isshelding = false
script.Parent.Equipped:Connect(function()
equipped = true
local hud = script.Parent.hud.SugaAttacks:Clone()
hud.Parent = game.Players.LocalPlayer.PlayerGui
local sugarpasteground = game.Workspace:FindFirstChildOfClass("Part").Material == Enum.Material.Slate
script.Parent.Part.Attachment.Flare:Emit(1)
script.Parent.Part.Attachment.Sparkle:Emit(1)
script.Parent.Part.Attachment.Wave:Emit(1)
game.Players.LocalPlayer.PlayerGui.HealthBarGui.CurrentFruit.Text = "Current Fruit : Suga Suga Paste O'No Mi"
end)
script.Parent.Unequipped:Connect(function()
equipped = false
game.Players.LocalPlayer.PlayerGui:FindFirstChild("SugaAttacks"):Remove()
game.Players.LocalPlayer.PlayerGui.HealthBarGui.CurrentFruit.Text = "Current Fruit : None"
end)
function sugarshot(inputObject, gpe)
if equipped == true then
if inputObject.KeyCode == Enum.KeyCode.Z and not gpe then
if debounce == false then
if isshelding == false then
debounce = true
script.Parent.Remotes.SugarShot:FireServer(game.Players.LocalPlayer:GetMouse().Hit.Position)
print("ahah")
wait(2.5)
debounce = false
end
end
end
end
end
function candycrush(inputObject, gpe)
if equipped == true then
if inputObject.KeyCode == Enum.KeyCode.X and not gpe then
if debounce2 == false then
if isshelding == false then
debounce2 = true
script.Parent.Remotes.CandyCrush:FireServer(game.Players.LocalPlayer:GetMouse().Hit.Position)
print("ahah")
wait(5)
debounce2 = false
end
end
end
end
end
function sugarmonster(inputObject, gpe)
if equipped == true then
if inputObject.KeyCode == Enum.KeyCode.C and not gpe then
if debounce3 == false then
if isshelding == false then
debounce3 = true
script.Parent.Remotes.GumdropPipebomb:FireServer(game.Players.LocalPlayer:GetMouse().Hit.Position)
print("ahah")
wait(1)
debounce3 = false
end
end
end
end
end
function shield(inputObject, gpe)
if equipped == true then
if inputObject.KeyCode == Enum.KeyCode.X and not gpe then
if debounce4 == false then
isshelding = true
debounce4 = true
script.Parent.Remotes.Shield:FireServer()
print("ahah")
wait(0.7)
isshelding = false
debounce4 = false
end
end
end
end
UserInputService.InputBegan:connect(sugarshot)
UserInputService.InputBegan:connect(candycrush)
UserInputService.InputBegan:connect(sugarmonster)
UserInputService.InputBegan:connect(shield)