For my Anti-Exploit, whenever Player.CharacterAdded fires I use CollectionService to give the player a tag showing the just spawned in case they spawned in the air, that way it doesn’t trigger the anti-tp.
I use spawn() to create a new thread which waits 5 seconds then removes the tag from the player.
My game’s servers are quite full and some lag has come from this new anti-exploit I implemented—I’m trying to determine if this is why. I assumed CollectionService is pretty efficient as it’s not that resource heavy, but I’m asking here just in case.
I would get rid of spawn in favor of RunService.Heartbeat:
local heartbeat = game:GetService"RunService".Heartbeat
local function spawn(f, ...)
local args = table.pack(...)
local c;
c = heartbeat:Connect(function()
c:disconnect()
f(table.unpack(args, 1, args.n))
end)
end
Due to the task scheduler controlling it, spawn() is really bad in mass numbers and can cause some major performance hits. This method is a lot more efficient.
You may have to supply some more details, perhaps some snippets of your code in order for people to fully understand what else might be causing the performance penalties. It’s hard to provide a good solution with such little information to work off of.