Ok so I have a game with bullets and to optimize the game I made this thing where multiple bullets use a table of values, my problem here is I cannot get the table from _G.
Heres the scripts:
The script that creates the tables and puts them into a table in _G.
local BulletStats = {}
script.CreateStat.Event:Connect(function(sentbulletstats)
local stattable = {{sentbulletstats[2],sentbulletstats[3],sentbulletstats[4],sentbulletstats[5],sentbulletstats[6],sentbulletstats[7],sentbulletstats[8],sentbulletstats[9],sentbulletstats[10],sentbulletstats[11],sentbulletstats[12]}}
table.insert(_G[sentbulletstats[1]],stattable)
end)
local bulletStatsTable = {BulletStats}
table.insert(_G,1,bulletStatsTable)
script.CreateStat:Fire({1,1,0,0,0,0,0,0,false,false,100,false})
The script that moves the bullets by getting table values(i made some debugs to check if the table value is nil and im getting fps drops to 2 fps).
if v:IsA("BasePart") then
local groupnumber = v:GetAttribute("StatGroup") + 1
local statsd = _G[1]
local stat = nil
local number = 1
for i,v in pairs(statsd) do
print(v)
if number == groupnumber then
stat = v
end
number += 1
end
if stat then
local Speed = stat[2]
local Slowdown = stat[4]
local Slowlimit = stat[3]
local Spin = stat[5]
local SpinAmount = stat[6]
local SpinLimit = stat[7]
local shieldDamage = stat[8]
local ShieldDestroy = stat[9]
local borderDestroy = stat[10]
local Lifetime = stat[11]
local rotation = v.Orientation
if Speed then
v.CFrame *= (CFrame.new(0,0,-Speed * Multiplier))*CFrame.Angles(0,Speed * Multiplier,0)
if Lifetime < 0 then
v:Destroy()
end
end
The scripts may be overcomplicated because its 4 am and i tried a lot of ways to solve this issue but i always get this error(the debugs removed from the script):
Players.Ghostisnothere2098.PlayerGui.BulletMove:63: attempt to compare nil < nil
the table just prints out as: nil nil nil nil nil nil nil nil nil nil nil nil
i will probably respond to the comments after 9 hours or so.
any help would be greatly appreciated.