I’ve been thinking of handling all Hits by a gun using 1 RemoteEvent but my issue is what if 20 or more players hit someone at the same time then wouldn’t the remote event throttle?
For example, I have 1 Hit RemoteEvent in replicatedstorage and whenever a player hits another player or an object it fires, the server then checks if it was a player, etc. But what if 20 players were to hit an object or hit a player at the same time then I’m pretty sure the RemoteEvent limit would have been reached and it would begin to throttle.
The Developer Hub says that a RemoteEvent can be fired 20 times per second. If you plan on having a lot of players in your game, you may try to split it by creating more RemoteEvents dynamically according to individual players or a group of players.
I’m thinking about having either a set of RemoteEvents in the tool or whenever a player joins I create a folder with the hit remote event in it and whenever a player shoots it fires the remote event under their folder. I’m not sure if this is a good way to solve this though.
Then I’d recommend splitting it into 2 events minimum, up to 4 maximum if you want to be safe. Make all the RemoteEvents handled by the same script and make the Client decide which RemoteEvent to use based on the player count. (e.g: If they’re the 30th player, they’d use the 3rd RemoteEvent.)
Instead of for every 10 players, 1 remote is created then couldn’t I just create 1 Remote event for every player that joins and whenever that specific player wants to shoot they will fire the remote event that was created for them by the server?
You could, but you’d have to load up every RemoteEvent created on the server dynamically. You’d end up loading 30-40 RemoteEvents maximum and that’s way too much, it’s better to group the players into 3 RemoteEvents than have 30 separate ones.
Yeah, I think Im going to go with this but, would the RemoteEvents still throttle sometimes? In my case since I have a red and blue team I could have a remote event for each team.
-- Server Script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent1 = ReplicatedStorage.RemoteEvent1
local RemoteEvent2 = ReplicatedStorage.RemoteEvent2
local RemoteEvent3 = ReplicatedStorage.RemoteEvent3
local RemoteEvent4 = ReplicatedStorage.RemoteEvent4
local function doSomething(player)
-- do something
end
RemoteEvent1.OnServerEvent:Connect(doSomething)
RemoteEvent2.OnServerEvent:Connect(doSomething)
RemoteEvent3.OnServerEvent:Connect(doSomething)
RemoteEvent4.OnServerEvent:Connect(doSomething)
-- Client Script
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent1 = ReplicatedStorage:WaitForChild("RemoteEvent1")
local RemoteEvent2 = ReplicatedStorage:WaitForChild("RemoteEvent2")
local RemoteEvent3 = ReplicatedStorage:WaitForChild("RemoteEvent3")
local RemoteEvent4 = ReplicatedStorage:WaitForChild("RemoteEvent4")
local function doSomething()
local playerNumber: number = 1
for i, plr in ipairs(Players:GetPlayers()) do
if plr.Name == Player.Name then
playerNumber = math.ceil(i/10)
end
end
if playerNumber == 1 then
RemoteEvent1:FireServer()
elseif playerNumber == 2 then
RemoteEvent2:FireServer()
elseif playerNumber == 3 then
RemoteEvent3:FireServer()
elseif playerNumber == 4 then
RemoteEvent4:FireServer()
else
print("what happened")
end
end
doSomething()
No, with 40 players and 2 RemoteEvents you’d have 20 players per RemoteEvent. Aside from the very low chance they all shoot at the same time, they’d still fit into the 20 activations per second of the RemoteEvent.
Yes, but that’s not something you can prevent unless you check if the exploiter is firing the RemoteEvent of the opposite team. If a person is firing the other team’s Remote Event then they’re obviously exploiting.
BlueTeamRemoteEvent.OnServerEvent:Connect(function(player)
if player.TeamColor == BlueTeam.TeamColor then
-- do something
else
player:Kick("Dont hack lil bro")
end
end)