So I have a gun, which I want to make as secure as possible. For this, you need remote events. So to make this gun automatic, I have to detect when the mouse is held or let go of. The problem is, when the gun is held, you have to update the mouse’s position constantly, while making sure that the client wait time is in sync with the server’s debounce. For example:
Server
local debouncetable = {}
game.ReplicatedStorage.Remote.OnServerEvent:Connect(function(plr, mouseposition)
if debouncetable[plr.Name] == nil or debouncetable[plr.Name] == false then
debouncetable[plr.Name] = true
print("Gun fired at" .. mouseposition)
wait(2)
debouncetable[plr.Name] = false
end
end)
Client
repeat game.ReplicatedStorage.Remote:FireServer(mouse.Hit.Position) wait() until Held == false`
With this method, the client and server aren’t gonna be in sync all the time, causing a lot of input lag. Also, the remote event limit is more likely to be reached. Is there any more efficent way to do this?