if not shared.lagcomps then
print("New lag comp!")
shared.lagcomps = {}
end
I doubt it’s a race condition as each new actor that contains this script is added like this:
players.PlayerAdded:Connect(function(player)
local hitbox = script.Hitbox:Clone()
hitbox.Name = player.Name
hitbox.Parent = replicatedstorage.Hitboxes
local actor = Instance.new("Actor")
local worker = script:Clone()
worker.Player.Value = player
worker.Parent = actor
workers[player] = actor
actor.Name = player.Name
actor.Parent = threads
end)
Why is shared.lagcomps nil across the threads? Am I misunderstanding something?
Each actor runs in its own environment and the shared table may not work as a global table across different actors, you can do this by creating a SharedTable using the SharedTableRegistry Service
local SharedTableRegistry = game:GetService("SharedTableRegistry")
local sharedData = SharedTable.new()
SharedTableRegistry:SetSharedTable("MySharedData", sharedData)
Access this shared table in your actors using the SharedTableRegistry .
local SharedTableRegistry = game:GetService("SharedTableRegistry")
local sharedData = SharedTableRegistry:GetSharedTable("MySharedData")
if not sharedData.lagcomps then
print("New lag comp!")
sharedData.lagcomps = {}
end