Cooldown for my gui attacks

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
image

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)

1 Like

I’ve created a system like this before. I won’t get down to the specifics, but it’s not secure to place the cooldowns locally. You should have a middle man security check on the server, before executing any attacks.

how would i do that?? and why placing the cooldown locally are not safe?

It has to do with the client server boundary. Anything on the client is insecure, because it be manipulated or removed. Instead, create values of the cooldowns, and tell the server which attack you want to choose, and then let the server check the cooldowns.

umm but how would i make the values on the server? like do i put the cooldowns on the script of the remote event? and about that gui cooldown, how could i do that