hello, I have a system that calculates positions of npcs relative to the grid below them, it uses a server script that loops through every npc 10 times a second, sends a message to the first actor which then sends a message to the second actor, both actors are fairly simple:
--actor1
local returnevent = script.Parent.Parent.ReturnSignal
local workersrepfolder = game.ReplicatedStorage.Workers
local actor2 = script.Parent.Parent.Actor2
@native function getgridpos(number)
return math.floor((math.floor(((number - 1) / 5) + 0.5) * 5) + 1) --remember: 1 is offset here
end
script.Parent:BindToMessageParallel('Instruction', @native function(instruction)
local s1 = getgridpos(instruction[1])
local s2 = getgridpos(instruction[2])
task.synchronize()
local id = game:GetService('HttpService'):GenerateGUID(false)
actor2:SendMessage('Instruction', {tostring(s1) .. tostring(s2), instruction[3]})
--print('event fired with id ' .. id)
end)
--actor2
repeat wait() print('waiting') until workspace.TerrainFinishedGenerating.Value == true
local workersrepfolder = game.ReplicatedStorage.Workers
local resultnum
local tabletoinclude = {}
for i, v in ipairs(workspace.CloseUpGrids:GetDescendants()) do
print(i, v)
if v.Name == "Grid" then
table.insert(tabletoinclude, v)
end
end
local postable = {}
for i, v in ipairs(tabletoinclude) do
print(i, v)
postable[tostring(v.Position.X) .. tostring(v.Position.Z)] = v
end
--all of the tables above only run once as the map is done generating and never again
script.Parent:BindToMessageParallel('Instruction', @native function(instruction)
local curgrid = workersrepfolder:FindFirstChild(instruction[2].ID.Value, true).CurrentGrid
local val = postable[instruction[1]]
task.synchronize()
curgrid.Value = val
end)
all in all, while simulating 1000 npcs, it should logically have a combined rate of no higher than 20000 ((1000 + 1000) * 10), however, the rate ends up being in the hundreds of thousands for BOTH scripts, while the script activity is relatively low
and the script rate increase looks like this, which would normally suggest a recursive loop somewhere
any ideas?