Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ##Your Question
- > Can someone please clarify why this error message occurs, what kind of affects it has on game scripts and which scripting practices are best to prevent this?
- ##My Answer
- If you fire an event to much it will throttle. Meaning it will stop queuing incoming remote event requests from clients. This can be terrible at times. If you are firing a remote 1000 times a second and then suddenly a player can't play anymore because the server started throwing out their remote event request could be bad. Some easy ways to prevent this is to prevent the client from sending to many requests per minute and limiting themself. *(Do these debounce checks or whatever on the client)*
- ###Example Code
- ~~~~~~~~~~~~~~~~~
- --// client example:
- local replicatedStorage = game:GetService("ReplicatedStorage")
- local event = replicatedStorage:WaitForChild("Event")
- local canFire = true
- local function fireDebouncedEvent(event, ...)
- if canFire then
- canFire = false
- event:FireServer(...)
- wait(.125)
- canFire = true
- return print("Successful event fire")
- end
- return warn("Attempted to post to many requests")
- end
- fireDebouncedEvent(event, "hello server")
- ~~~~~~~~~~~~~~~~~
- Every `.125` seconds you can fire the event again with the passed args.
- You can also try doing checks on the server to see if a client is spamming your event such as logging how many requests they make a minute and if it to high then kick them.
- ###Example Code 2
- ~~~~~~~~~~~~~~~~~
- local replicatedStorage = game:GetService("ReplicatedStorage")
- local players = game:GetService("Players")
- local event = replicatedStorage:WaitForChild("Event")
- --// settings
- local fires = {}
- local clearFires = true
- local maxRequestsPerMinute = 1000
- local function handleOnServerEvent(player, ...) --// handle event
- if fires[player] <= maxRequestsPerMinute then
- fires[player] = fires[player] + 1
- return print(player, "sent information: ", ...)
- end
- return player:Kick("Spamming events")
- end
- local function addToFiresTable(player) --// add new players to fires
- fires[player] = 0
- end
- players.PlayerAdded:Connect(addToFiresTable)
- event.OnServerEvent:Connect(handleOnServerEvent)
- while clearFires do --// clear every 60 seconds
- for i, player in next, fires do
- fires[player] = 0
- end
- wait(60)
- end
- ~~~~~~~~~~~~~~~~~
- ###Extra
- I kinda was to lazy to test any of the code I wrote on this answer. If it doesn't work it at least should be a good foundation on how to do something like this.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement