Greetings all, I have a gun system which has a limit on how fast one can use it. My small dilemma is whether I should handle a cooldown on the client, or server.
It's a little hard to explain, so bear with me At its current state, the client handles the cooldown, as shown below
--just and example
--LocalScript
local mouse = game.Players.LocalPlayer:GetMouse()
local event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
local debounce = true
mouse.Button1Down:Connect(function()
if debounce then
debounce = false
event:FireServer()
wait(0.25)
debounce = true
end
end
--Server script
local event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
event.OnServerEvent:Connect(function()
--code here
end)
I've taken note that exploiters could just fire the event as they please, no cooldown. I tried putting the cooldown in both the server and client, but the gun fires slower. Would allowing the event to be spammed slow anything down? Like exhaust the script? Here's how the server would handle the debounce
--LocalScript
local mouse = game.Players.LocalPlayer:GetMouse()
local event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
mouse.Button1Down:Connect(function()
event:FireServer()
end
--Server script
local event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
local debounce = true
event.OnServerEvent:Connect(function()
if debounce then
debounce = false
--code here
wait(1)
debounce = true
end
end)
