Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Table's table.insert breaks after one use? [SOLVED]

Asked by 8 years ago

I have a player join, upon joining a history table is created to save their purchases, their history table is updated with their previous purchases transferring them from the datastore by using unpack(), if they want to buy something the click the GUI which sends an Event signal to tell the script to calculate if they can buy the item, if not it returns a print("[System]: Already bought.") However, upon joining the datastore fires an event which sets the history table to the users previous purchases, using table.insert, if I don't do this the player can re-buy what they already have. However, when I try to use table.insert when the player buys something else, it doesn't insert into the table, I have no idea why, why apparently whenever I unpack the datastore key as a table and send it to be the history table, then try to insert something it doesn't work.


-- Event that hosts all purchases made by the player. 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 I will fix later iterating through all the strings of chardata. --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[player]), "b4 insert") table.insert(history[player], id) --ID is the item's name being purchased, it inserts it into the players table, which is saved afterwards so they can't re-purchase it, however it inserts nothing, as I have these print functions telling me so, how can I fix this? print(unpack(history[player]), "after insert") Characters:SetAsync(user, unpack(history[player])) print(saves, "after setasync") end end end) --Event that listens from 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) end)

Any clarifications or code needed I can provide it.

EDIT: Solved by re-writing the code in a different way, perseverance will usually get the job done!

1 answer

Log in to vote
0
Answered by
nobo404 17
8 years ago

I think the problem is that there isn't a loop. I don't see one, so it might be running the whole code only once. If there is a loop around it that you didn't include, then I can't help you. :(

Ad

Answer this question