Why are the points not saving properly?
Im trying to save the players stat points and it works nice, but for some reason its not working for melee everytime, here is the script:
01 | local DataStore = game:GetService( "DataStoreService" ):GetDataStore( "StatsDataStore" ) |
02 | game.Players.PlayerAdded:Connect( function (player) |
03 | local MeleeName = "MeleeP" |
04 | local folder = player:WaitForChild( "Data" ) |
05 | local MeleeP = player:FindFirstChild( "Data" ):WaitForChild( "MeleeP" ) |
06 | local ID 2 = MeleeName.. "-" ..player.UserId |
09 | savedData = DataStore:GetAsync(ID 2 ) |
12 | if savedData ~ = nil then |
13 | MeleeP.Value = savedData |
18 | print ( "New player to the game" ) |
21 | local MeleeName = "MeleeP" |
22 | game.Players.PlayerRemoving:Connect( function (player) |
23 | local ID 2 = MeleeName.. "-" ..player.UserId |
24 | DataStore:SetAsync(ID 2 ,player.Data [ MeleeName ] .Value) |
27 | game:BindToClose( function () |
31 | for i, player in pairs (game.Players:GetPlayers()) do |
33 | player:Kick( "This game is shutting down" ) |
Thank you!