So, essentially I have a datastore, fire a BindableEvent to my leaderboard, which has the players purchase history, the history is a table which is filled with strings by using unpack(table) the history is set using the event and then upon a GUI button fires an event that goes to the leaderboard with the ID which is a string that is a variable inside the GUI's button's script, that is then inserted into the table, using table.insert, however it clears out the previous thing in there, is there a way to get around this or, what am I missing, also, will the:
if id == chardata then
--do code
else
--do code
end
scan through the entire number of strings provided if not, would I use a: for _, k etc. to see if the the strings match the id the GUI button provided?
EDIT: Would it be easier to unpack a table unpon the player joining, or save all of the history as strings, because of the limit a datastore can hold? Also, how many strings can it hold, as I plan on this holding about 100-200+ overtime, all will be about 5-12 characters long, if that is needed.
Leaderboard:
--This event handles all the GUI button purchases.
moneye.Event:connect(function(cost, plr, id)
if cost <= playerLeaderstats[plr]["Cash"] then
local user = "User_" .. plr.userId
local saves = Characters:GetAsync(user)
local chardata = saves
print(id,"id should be " .. chardata )
if id == chardata then --This is the line I have the question above on, since there will be more than one string will it automatically search through all of them or not?
--print(unpack(history), "TESTETET")
return print("[System]: Already bought.")
else
playerLeaderstats[plr]["Cash"] = playerLeaderstats[plr]["Cash"] - cost
cashe:Fire(playerLeaderstats[plr]["Cash"])
print(unpack(history[plr]), "b4 insert")
table.insert(history[plr], id) --Error is here, it overwrites the previous string inside the table, how do I make it not do that?
print(unpack(history[plr]), "after insert")
Characters:SetAsync(user, unpack(history[plr])) --This assures the the table will be packaged as all strings, the strings will then load next time the player joins so they can't re-purchase a product they already have, the whole reason for inserting the ID into a table then saving it to a datastore.
print(saves, "after setasync")
end
end
end)
--This event is the event fired from the datastore
historye.Event:connect(function(data, plr)
if plr.userId == player.userId then
print("received")
print(data)
print(unpack(history[plr]), "before")
local insertthis = data
table.insert(history[plr], insertthis)
print(unpack(history[plr]), "after")
else
return print("error")
end
end)
GUI Button:
script.Parent.MouseButton1Click:connect(function()
local tofire = plr:FindFirstChild("Events").MoneyTransfer
local id = "TestA"
tofire:Fire(COST, plr, id)
end)
If any more code is needed I will provide it, thanks for any help.

2 comments
check this article out https://scriptinghelpers.org/questions/28244/best-way-to-mass-save-data#31696
Glad you listened to me and added a history table :)