Does multiple scripts modifying same table cause lag?

I have a table that constantly updates the subtables : Survivors, Zombies.
Explosion functions, bullet functions, zombiearm touch functions etc. All use same table to check who they hit, where enemies are etc.

Ever since this was added my game has been experiencing extremly frequent crashes. I’ve monitored this list and it doesn’t hog up on old data. Only the players/mobs available are listed.
What seems to be happening is that if multiple scripts access this table at same time it creates tremendous lag.

Is this possible or could something else be causing this extreme lag?

1 Like

Hi there,

This is something that you can actually check for yourself using the Micro Profiler http://robloxdev.com/articles/MicroProfiler

If you add debug.profilebegin() and debug.profileend() to your code you can actually see this custom labels popping up. It takes some knowledge to be able to read the Microprofiler, but ROBLOX has documented it quite well. You can also dump the microprofiler to your localmachine, so you can analyse it in peace :wink:

It also sounds like you don’t do garbage collection like you should, perhaps take a look or that is the case ?

Thing is the whole server crashes and I’m unable to get logs from that :confused:

How can I check if Im doing GC correctly? (I’m utterly useless at this)

You should try using the lua debugger, it can prevent studio from freezing from stuff like this:
image
You can use it to inspect the table if it’s not cyclic. Just add a breakpoint on the line after you have a reference to it.

Beware that you cannot step into metamethods, because they cannot yield.
Do not use print at a very fast rate, it can cause lag to write to the disk or to render.

How are you achieving multiple script access?
Do you have any metatables?
Which scripts and functions are writing? Which are reading? At what rate?

How are you monitoring the list right now?

I suppose you have a similiar setup to:

  • root table
    • Survivors
    • Zombies

How many references do you have on any of these tables?

I imagine the table is in a ModuleScript, and he’s changing values that way. That’s what I’m doing for my RPG game and it’s been working fine so far.
@PlaceRebuilder Are you removing references to players or enemies once they have been removed from the game? Over time, this could build up and create a lot of useless references.

1 Like

Module, only the module are allowed to change the table, others just read it (and edit it’s referenced parts like torso)

Each object looks like this:
local t = {Name, Torso, Humanoid, Player, Char, isSurvivor}

But I also have this:

if not revivable then
	local conn = nil
	conn = humanoid.Died:connect(function()
		conn:disconnect()
		removeTable(t)
		source[char] = nil
	end)
end

50+ references on server atleast. Mostly from NPCs but also from explosions and campaign objectives etc.

Would this be sufficient?

function clear(t)
	for i,v in pairs(t) do
		t[i] = nil
	end
end

function clearAll()
	for i,t in pairs(TARGETS) do
		clear(t)
	end
end

Basically just clear all sub-tables (Survivors, Zombies, Enemies (client-side only))

Here is a microprofile just seconds before a crash:
https://ufile.io/sa1a0

Here is after it crashed:
https://ufile.io/4v1w2

I can’t see anything (besides roblox useless translate service) that hogs the system.

I don’t have enough enough information and so I can’t know wether the tables you are using
are the cause of the crashes. I will suppose your game is built this way:

  • TARGETS (stored in a modulescript)
    • Survivors
      • {Name, Torso, Humanoid, Player, Char, isSurvivor}
    • Zombies
      • {Name, Torso, Humanoid, Player, Char, isSurvivor}
    • Enemies
      • {Name, Torso, Humanoid, Player, Char, isSurvivor}

Wether modifying tables crash a game or not is place-specific, it can be caused by scripts that have a bad table management causing infinite loops, serilialization, etc.

Is the table kept on the server or the client too? How are you replicating it’s structure?

I suppose this is due to using multiple scripts, they could be hogging memory?

The only I think I could have seen as the cause of the lag is the same of this post