Laggy touched events

when a player collects multiple coins & gems at once, the server gets laggy… On computer it doesn’t affect the performance much, but on mobile it almost freezes everything.

the coins and gems have pretty massive hitboxes so that they can be collected from a longer distance.
the coin is displayed with a billboard gui.
currency

in game, the orbs are usually this close to each other.
currency2

script:

coin.Touched:Connect(function(hit)

if db == false then
		
		if game.Players:GetPlayerFromCharacter(hit.Parent) then
				
			db = true	
				
			if (hit.Position - coin.Position).magnitude < 10 then	
					
				-- give currency
					
			else	
				-- player was not close enough		
					
				db = false	
					
			end
		end
	end

end)

1 Like

By looking at your code, you pretty much just erased your denounce with the distance check. Trying adding task.wait(1) if they are not within the range.

the magnitude check is there because of exploiters. I immediately set it back to true so that it doesn’t affect other players, in case an exploiter collected the coin 200 studs away

So does it lag when you’re actually within range and touch the part?