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

Can't find the logical error in my code [Datastores]?

Asked by 8 years ago

Hello.I've spent at least a few hours now trying to debug/find the error of what is causing the issue to occur,but to no avail.Here is my issue:

When a Player joins the game,their data is loaded from the datastore and put into their data folder in ServerStorage.

When a Player leaves the game,their data is put into a metatable and saved to the datastore.

Pretty straightforward,until the bug comes in.

For some odd reason,the weapons and pets that the player owns are cloned repeatedly inside the datastore.Also,data between two players gets mixed together for some odd reason..

For example:

Player A owns the weapon "LinkedSword".It is saved in the 'Weapons' metatable,and inside the 'Weapons' folder when loaded into his/her datafolder.Player A owns the pet "Doge",which is saved inside the 'Pets' metatable,and inside the 'Pets' folder when loaded into the datafolder.

With Player B,the same scenario is in place with how the data is stored. Player B owns the weapon "GolfClub",and owns the pet "Kitty".

All runs well,when the player joins their data is loaded into the server,when they leave the data is put inside a metatable and saved to the datastore.But here's the problem:

Next time Player A's data is loaded,he/she now owns the pets "Doge" and "Kitty" and "Kitty" and "Kitty" (Yes,the cloning is what happens).Same with the saved weapons.The data seems to "Cross" between the two players,even though they have their own seperate datafolders.

I am completely stumped.If someone can point out the logic error,please do. Thanks!

Here is the code:

DataService script:

001--[[
002 
003    Data Service
004    Handles the loading,saving,and handling of user data.  
005 
006--]]
007 
008--Waiting for the main framework to load.
009_G.DataServiceReady=false
010while _G.ServerReady==nil or _G.ServerReady==false do
011wait()
012end
013--Calling the datastore service
014local DataStore=game:GetService("DataStoreService"):GetDataStore(_G.Config.DataStoreName)
015 
View all 112 lines...

PlayerEvents script:

01--[[
02 
03    Player Service
04    Handles player events,such as spawning,joining,dyeing,etc. 
05 
06--]]
07 
08--Defining Services and vairables
09local PlayerService=game:GetService("Players")
10 
11--Configuring the services and vairables
12PlayerService.CharacterAutoLoads=false
13 
14--Player joined event
15PlayerService.PlayerAdded:connect(function(Player)
View all 37 lines...
0
There is a lot that needs to be looked at here, none of your data store processing is 'safe' and there is no need to use global variable her at all. User#5423 17 — 8y
0
I use global functions so I don't have to type in the same code again and again. Reshiram110 147 — 8y
0
We use module scripts. User#5423 17 — 8y
0
I use module scripts as well. I tend to use them as a library. Reshiram110 147 — 8y

Answer this question