So I added a new datastore to a project a few days ago, then got the idea for an XP multiplier to go with the data, the problem is I don’t know how to add the values to the table labeled correctly.

When I try and do
local levelstats = {Level = 0, CurXP = 0, MaxXP = 238}
local XPMult ={Mult = 0, Timer = 0}
table.insert(levelstats,XPMult)
print(levelstats)
the final print is that screen shot. I need the table to look like
{Level = 0, CurXP = 0, MaxXP = 238, XPMult ={Mult = 0, Timer = 0}}
rather than
{Level = 0, CurXP = 0, MaxXP = 238, [1] ={Mult = 0, Timer = 0}}
Anyone know how to fix this?
Table .insert directly inserts the table into the stats, I believe you are looking to copy the key value pairs from one table to the other instead.
local levelstats = {Level = 0, CurXP = 0, MaxXP = 238}
local XPMult ={Mult = 0, Timer = 0}
--table.insert(levelstats,XPMult)
for key,value in pairs(XPMult) do
levelstats[key] = value
end
1 Like
Wasn’t quite what I was looking for but it did help me! and i did get it looking correct.
yours would look like
{Level = 0, CurXP = 0, MaxXP = 238, Mult = 0, Timer = 0}
but I wanted
{Level = 0, CurXP = 0, MaxXP = 238, XPMult ={Mult = 0, Timer = 0}}
but with your method changed up a little I did get it how I wanted!
1 Like