I think I’m sending way to many remote events and I feel like multiple are being ignored.
You’re most likely sending way too many remote events and exhausting the event invocation queue. In other words, the server can’t keep up with the amount of events being fired from each client, which is a likely situation given your current structure for your turret system.
First, you shouldn’t want to constantly fire the RemoteEvent to move the turret. Depending on how many turrets you have, and how many players can move those turrets, it can be enough to worsen latency for all players if the server has to process an absurd amount of remote events given (or ignore them, as you’ve already described).
Ideally, you’ll want to only fire an event where needed to let the server know when to begin moving or when to end moving the turret. It can look like this on the client:
local RIGHT_TRAVERSE = Enum.KeyCode.D
UIS.InputBegan:Connect(function(input)
if (is_gunner) and input.KeyCode == RIGHT_TRAVERSE then
local contrl_db = true -- not sure what this is used for
game.ReplicatedStorage.GunControls:FireServer(RIGHT_TRAVERSE, "StartMoving")
end
end)
UIS.InputEnded:Connect(function(input)
if (is_gunner) and input.KeyCode == RIGHT_TRAVERSE then
local contrl_db = true -- not sure what this is used for
game.ReplicatedStorage.GunControls:FireServer(RIGHT_TRAVERSE, "StopMoving")
end
end)
You might be noticing why we’re passing in an additional parameter - that’s to let the server know how the turret should respond with the information passed in by the client. You would shift your rotation mechanism entirely on the server after that:
local RIGHT_TRAVERSE = Enum.KeyCode.D
local isMoving = false
game.ReplicatedStorage.GunControls.OnServerEvent:Connect(function(plr, control, moveAction)
if (control == RIGHT_TRAVERSE) then
if moveAction == "StartMoving" and not isMoving then
isMoving = true
while isMoving do
rotation = CFrame.Angles(0, math.rad(0.5), 0)
script.Parent.Canon.CFrame = script.Parent.Canon:GetPivot()
script.Parent.Canon:PivotTo(script.Parent.Canon.CFrame * rotation)
task.wait(0.1)
end
elseif moveAction == "StopMoving" and isMoving then
isMoving = false
end
end
end)
Of course, this isn’t the most ideal way to implement this - this is just a rough structure of what it could look like. Depending on how many turrets you have, you’ll probably want to use a dictionary or capture something onto the object itself instead of using a singular variable to control rotation, and implement sanity checks to ensure that cheaters shouldn’t be able to move turrets if they are unable to according to your game logic.
Hope this helps