When rejoining the game my stage value that was saved is randomized?
Now, i'm unsure if this is happening to players playing the game, but it has been happening for me and the game owner.
I have a datastore scirpt which loads the player's data when joining and saves it when leaving the game. However whenever I rejoin, most of the time my stage would be completely random.
01 | local DS = game:GetService( "DataStoreService" ):GetDataStore( "SomeDataButItsNotTheActualName" ) |
03 | game.Players.PlayerAdded:connect( function (plr) |
04 | local leaderstats = Instance.new( "Model" ) |
05 | leaderstats.Name = "leaderstats" |
06 | leaderstats.Parent = plr |
08 | local stage = Instance.new( "NumberValue" ) |
10 | stage.Parent = leaderstats |
12 | local cash = Instance.new( "NumberValue" ) |
14 | cash.Parent = leaderstats |
16 | local success, st = pcall ( function () |
17 | return DS:GetAsync( "plr_" .. tostring (plr.UserId)) |
22 | game:GetService( "ReplicatedStorage" ).Notify:FireClient(plr) |
27 | game.Players.PlayerRemoving:connect( function (plr) |
28 | local success, fail = pcall ( function () |
29 | DS:SetAsync( "plr_" .. tostring (plr.UserId), stage.Value) |
36 | local good, fail = pcall ( function () |
37 | DS:SetAsync( "plr_" .. tostring (plr.UserId), stage.Value) |
39 | if good then break end |
(snipped out irrelevant parts of the script)
So, what am I doing wrong?