Money data gets reseted in studio sometimes??
Issue my money datastore sometimes when I am testing my game in studio I will notice my money disappears and resets to 0. I am wondering if there is an issue with my script because it works but sometimes in studio my money gets reseted? Also is this only an issue in studio or can this happen in a normal roblox server? Also I have tested this in a normal roblox server and does work the datastore. Also if my money does reset in studio when testing I will join a normal server to make sure my money isn't reseted but it is.
Script in serverscriptservice
01 | local DSS = game:GetService( "DataStoreService" ) |
02 | local DataStore = DSS:GetDataStore( "MYData" ) |
06 | game.Players.PlayerAdded:Connect( function (player) |
07 | local leaderstats = Instance.new( "Folder" ) |
08 | leaderstats.Name = "leaderstats" |
09 | leaderstats.Parent = player |
11 | local Money = Instance.new( "IntValue" ) |
13 | Money.Parent = leaderstats |
16 | local success, errorMessage = pcall ( function () |
17 | data = DataStore:GetAsync(player.UserId) |
19 | if success and data ~ = nil then |
20 | print ( "Data successfully loaded!" ) |
21 | Money.Value = data.Money |
27 | game.Players.PlayerRemoving:Connect( function (player) |
28 | local leaderstats = player.leaderstats |
30 | Money = leaderstats.Money.Value; |
33 | local success, errorMessage = pcall ( function () |
34 | DataStore:SetAsync(player.UserId,data) |
37 | print ( "Data successfully saved!" ) |