Im making a simple coin collect system.
The Coins are rendered on client but the coin information is saved on server AND client.
Im using Heartbeat to animate all coins and to check if the player is in range.
If the player is in range it will invoke a remote but due to server client character delay replication the client will send requests before the “server character” even hit that position [im using magnitude]
Add a debounce which will limit the amount of requests the client can send
For example:
local RemoteSendingCooldown = false
-- Coin touch event thread
if RemoteSendingCooldown == false
RemoteSendingCooldown = true
RemoteEvent:Fire()
task.wait(0.5)
RemoteSendingCooldown = false
else
return
end
This might not be perfect, but you can adapt it or use a better method if you want. Do not leave the excessive remote event firing ignored as this will cause a lot of data being sent to the server and may cause instability issues.
if (v:GetAttribute("Position") - char.HumanoidRootPart.Position).magnitude <= coinMagn.Value and v:GetAttribute("Threaded") ~= true then
v:SetAttribute("Threaded", true)
local collected = collectRemote:InvokeServer(v.Name)
print(collected)
if collected then
print("coin collected!")
v:Destroy()
else
task.wait(0.5)
v:SetAttribute("Threaded", false)
end
end
The server side remote is just checking the position [same pos as the client shows in the if statement] and then giving the player coins
This prevents the useless remote calls, but the range has gotten smaller now, cause the coin is setted into the debounce bcs of the delay
no, you do two checks, one on the client and one on the server, client need to validate if it’s visually appealing, and server if it’s logically appealing
thats what im doing
But the problem is that the client is sending the remote when the client character magnitude is true, but because of the delay between server and client character replication the server character is not inside that magnitude
then don’t care, 5-7 remotes with less data is pretty much nothing to worry about, you can add client-sided debounce, you can also check distance on client and block option to send requests until distance condition is changed
This a bad thing to say. Remote events have a limit of 20 events per second, and with such a bad issue which Lolly is experience this can cause the event to throttle.
From what source you’ve got that remotes events have a limit of 20 per second? because from what i know it’s not how their work and that they send secured packages to server that need to be accepted, and their depend on player connection, he also can use unreliable remotes which will send unsecured packages of various sizes and without order, no limits at all, only connection
EDIT: problem is that he can only add debounce, otherwise there is no really methood to fix that
Wait, one thing, do you use client to detect magnitude change or server? if server then u can change and use client and server checks to remove those unnecesary remote calls
So to make it clear how my system is working on the coins:
[CLIENT]
I have a heartbeat which animates every coin + checks if player is in magnitude and if thats true the event gets fired
[SERVER | REMOTE HANDLER]
After the remote got a request the server will check trough the coin id if the player is in the magnitude, just this time in server side and if thats true the player gets the coin and the coin gets deleted
So the magnitude will be checked on client AND server
The only problem is that the client detects it as true before the player is even inside the magnitude ON the SERVER
have you tried having a lower distance check on the client to the server to make up for it?, and if its inconsistent you could change it dynamically through getting the ping of the player and basing the distance off of that
See there is one thing, player have 100% control over character, soo if you don’t have any hitbox or smth, you shouldn’t do the magnitude check on server, at least not with reference, send position from client, you can optimize it by buffers if you really want, this way you can safely assume that client entered area, of course player still may get around it but it will be harder than normally
Also: Add tick based debounce to the server, then the remote requests wouldn’t be possible to crash the game
Roblox Lua is an event based programming language. This means that it’s more efficient to use events to trigger a coin being picked up rather than looping every heartbeat.
Using a Touched event on the client would be super simple and save a ton of memory on the client. It’s simple to set up a function for every coin to detect when it’s touched and then you can fire the remote from there and do your server checks.
To avoid the remote event being called multiple times add a debounce table on the client and insert the coin once it’s been touched. If you find the coin in the debounce then just return. The touched connections will also remove themselves after your destroy the coin.
Is there any reason why you can’t use this much more efficient method?
Btw if we talk about that, you don’t need heartbeat for that, you can use while loop with 1/10 frequency and check distance + correction percent, this way you can reduce your game stress by like 6-7x