I’m working on a gun system currently and the higher your fps is the faster you fire your gun. What is a good way at making sure everyone’s fire rate will be at the same time.
Add cooldowns on the server for the maximum amount of bullets each client can request to send.
Example:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local CanFireGun = {}
local DebounceTime = 0.05 -- 20 times per second max
Players.PlayerAdded:Connect(function(Player)
CanFireGun[Player.UserId] = true
end)
Players.PlayerRemoving:Connect(function(Player)
CanFireGun[Player.UserId] = nil
end)
local Remotes = ReplicatedStorage.Remotes
local FireGun = Remotes.FireGun
FireGun.OnClientEvent:Connect(function(Player)
if not CanFireGun[Player.UserId] then return end
CanFireGun[Player.UserId] = false
task.delay(DebounceTime, function()
CanFireGun[Player.UserId] = true
end)
--Do stuff here
end)
Use DeltaTime.
local gunCooldown = 0
runservice.PreRender:Connect(function(deltaTime)
if gunCooldown <= 0 then
gunCooldown = 0.2 --// 0.2 seconds
--// fire gun
else
gunCooldown -= deltaTime
end
end)