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 9 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.

01-- Event that hosts all purchases made by the player.
02moneye.Event:connect(function(cost, plr, id)
03    if cost <= playerLeaderstats[plr]["Cash"] then
04    local user = "User_" .. plr.userId
05    local saves = Characters:GetAsync(user)
06    local chardata = saves
07    print(id,"id should be " .. chardata )
08    if id == chardata then --This I will fix later iterating through all the strings of chardata.
09    --print(unpack(history), "TESTETET")
10    return print("[System]: Already bought.")
11        else
12    playerLeaderstats[plr]["Cash"] = playerLeaderstats[plr]["Cash"] - cost
13    cashe:Fire(playerLeaderstats[plr]["Cash"])
14    print(unpack(history[player]), "b4 insert")
15    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?
View all 43 lines...

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
9 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