Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Two scripts editing a table at the same time?

I have a JSON table stored in a StringValue. This table has every player's name in it, along with a true or false value for each person. One script changes the true/false value for each player depending on whether they are in a certain room or not. The other script adds and removes players if they are joining or leaving the game. Since the table is JSON in a StringValue, I worry that if both scripts run at the same time, one might nullify the others' changes.

Example

  1. Script #1 Gets the current table from the JSON StringValue

  2. Script #2 Gets the current table from the JSON StringValue

  3. Script #1 Changes Player4 to false and submits the new table to the JSON StringValue

  4. Script #2 Removes Player9 and submits the new table to the JSON StringValue --This table still remembers Player4 as true, thus nullifying Script #1's changes

So how might I solve this problem? Is there a way to make a globally editable table who's parts can be edited independently of each other?

1 answer

Scripts can't run at the same time; there is one thread. IF scripts yield then they alternate to different scripts. So as long as each one gets the latest string version often I can't imagine there would be a problem.

2 comments

0

Both Script #1 and #2 are really just functions that are activated by :connect(). In this case, I believe it is still possible for both functions to make this mistake (see Threading on the wiki).

0

ok you kinda just ignored me and repeated yourself.

This discussion is preserved as it was. New answers, comments, and votes are closed.