Datastore Not Saving all Values?
Asked by
5 years ago Edited 5 years ago
So I'm working with a data store in a racing game. The datastore is suppose to save the players money and miles driven and their rank. Also in a folder thats not leaderstats it's suppose to save cars that they buy. The script has been working fine for months but now all of the sudden it stopped saving everything in leaderstats, so the money{Rowg Coins} miles driven and rank. But it still saves the cars. Any suggestions would be greatly appreciated.
001 | local DSS = game:GetService( "DataStoreService" ) |
002 | local RepStorage = game:GetService( "ReplicatedStorage" ) |
004 | local RedlinePlayerDS = DSS:GetDataStore( "RedLineRacing-DS" ) |
005 | local EventTutorial = RepStorage.TutorialEvent |
007 | local PlayerDataTemplate = { |
008 | -- [ "Name" ] = { "ValueObject" , defaultValue } , |
009 | [ "Rowg Coins" ] = { "NumberValue" , 15000 } , |
010 | [ "Miles Driven" ] = { "NumberValue" , 0 } , |
011 | [ "Rank" ] = { "StringValue" , "Permit" } , |
012 | [ "Ae86" ] = { "BoolValue" , false } , |
013 | [ "180SX" ] = { "BoolValue" , false } , |
014 | [ "1968 Challenger" ] = { "BoolValue" , false } , |
015 | [ "911" ] = { "BoolValue" , false } , |
016 | [ "Accord" ] = { "BoolValue" , false } , |
017 | [ "Camaro SS" ] = { "BoolValue" , false } , |
018 | [ "Corvette Z06" ] = { "BoolValue" , false } , |
019 | [ "Huracan Performante" ] = { "BoolValue" , false } , |
020 | [ "LFA" ] = { "BoolValue" , false } , |
021 | [ "Lancer Evolution" ] = { "BoolValue" , false } , |
022 | [ "Miata" ] = { "BoolValue" , false } , |
023 | [ "ModelS" ] = { "BoolValue" , false } , |
024 | [ "Senna" ] = { "BoolValue" , false } , |
025 | [ "Supra" ] = { "BoolValue" , false } |
028 | game.Players.PlayerAdded:Connect( function (player) |
029 | local playerKey = "Player-ID:" ..player.UserId |
031 | local CarStorage = Instance.new( "Folder" , player) |
032 | CarStorage.Name = "OwnedCars" |
033 | local leaderstats = Instance.new( "Folder" , player) |
034 | leaderstats.Name = "leaderstats" |
035 | local RaceHolder = Instance.new( "Folder" , player) |
036 | RaceHolder.Name = "raceHolder" |
038 | for name, object in pairs (PlayerDataTemplate) do |
039 | local newValue = Instance.new(object [ 1 ] ) |
041 | newValue.Value = object [ 2 ] |
043 | if object [ 1 ] = = "NumberValue" or object [ 1 ] = = "StringValue" then |
044 | newValue.Parent = leaderstats |
046 | newValue.Parent = CarStorage |
051 | local success, message = pcall ( function () |
052 | GetSave = RedlinePlayerDS:GetAsync(playerKey) |
057 | print (player.Name.. "'s Data = {" ) |
058 | for _, object in ipairs (CarStorage:GetChildren()) do |
059 | if object:IsA( "BoolValue" ) then |
060 | print (object.Name, GetSave [ object.Name ] ) |
061 | object.Value = GetSave [ object.Name ] |
064 | for _, object in ipairs (leaderstats:GetChildren()) do |
065 | if object:IsA( "StringValue" ) or object:IsA( "NumberValue" ) then |
066 | print (object.Name, GetSave [ object.Name ] ) |
067 | object.Value = GetSave [ object.Name ] |
071 | print ( "Data loaded for " ..player.Name) |
078 | game.Players.PlayerRemoving:Connect( function (player) |
079 | local playerKey = "Player-ID:" ..player.UserId |
081 | local CarStorage = player:FindFirstChild( "OwnedCars" ) |
082 | local leaderstats = player:FindFirstChild( "leaderstats" ) |
083 | print (leaderstats [ "Rowg Coins" ] .Value, leaderstats [ "Miles Driven" ] .Value) |
085 | local tableToSave = { } ; |
087 | for _, object in ipairs (CarStorage:GetChildren()) do |
088 | if object:IsA( "BoolValue" ) then |
089 | tableToSave [ object.Name ] = object.Value |
092 | for _, object in ipairs (leaderstats:GetChildren()) do |
093 | if object:IsA( "StringValue" ) or object:IsA( "NumberValue" ) then |
094 | tableToSave [ object.Name ] = object.Value |
098 | local success, message = pcall ( function () |
099 | RedlinePlayerDS:SetAsync(playerKey, tableToSave) |
106 | print ( "saved success for " ..player.Name) |