I am adding new values to a datastore and the first 2 values, which I added before work fine, but the second 2 values always save as 0, and even when I print them during saving it says they are 0, when they are not, which makes the game always save it as 0. I have tried looking on the dev forum and changing the datastore I am saving to but nothing worked.
Here is the saving script
local ds = game:GetService("DataStoreService"):GetDataStore("SaveData2")
game.Players.PlayerAdded:Connect(function(plr)
local plrkey = "id_"..plr.userId
local save1 = plr.leaderstats.Plastic
local save2 = plr.leaderstats.Coins
local save3 = plr.ToolValues.ShopPurchased
local save4 = plr.ToolValues.EquippedItem
local GetSaved = ds:GetAsync(plrkey)
if GetSaved then
save1.Value = GetSaved[1]
save2.Value = GetSaved[2]
save3.Value = GetSaved[3]
save4.Value = GetSaved[4]
else
local NumberForSaving = {save1.Value, save2.Value, save3.Value, save4.Value}
ds:GetAsync(plrkey, NumberForSaving)
end
plr.PlayerGui.ScreenGui.PlasticAmount.TextLabel.Text = save1.Value.."/"..plr.PlayerGui.ScreenGui.PlasticAmount.TextLabel.MaxPlastic.Value
plr.PlayerGui.ScreenGui.CoinAmount.TextLabel.Text = save2.Value
end)
game.Players.PlayerRemoving:Connect(function(plr)
ds:SetAsync("id_"..plr.userId, {plr.leaderstats.Plastic.Value, plr.leaderstats.Coins.Value, plr.ToolValues.ShopPurchased.Value, plr.ToolValues.EquippedItem.Value})
end)
Funny how I had the same problem yesterday and here’s how I fixed them your problem is that It already saved the first 2 values so If GetSaved becomes true so the value of saving 3 and 4 get saved but there’s nothing saved for them (note this will not be a problem with new players cause their values hasn’t been saved) what you need to do Is two things one easy and another a little more annoying first is play in Roblox studio and go to sever and edit your player’s values on the sever than go-to player game mode and exit the game it should fix itself If Roblox studio datastore isn’t buggy 2nd way is to create a script that will change the player’s value but instead of being in Roblox studio be in Roblox on your game and click on the value which will save the values of 3 and 4 and they’ll no longer become nill
(Sorry for the late response)
Could you specify more about what you mean when you say things like “play in Roblox studio and go to sever and edit your player’s values on the sever than go-to player game mode and exit the game”
sorry for very late response but hope this helps people who are having this problem ive found a better solution insert this code after youve asigned the values for your datastore or its will bug
– i also added shirts and pants cause this apart of my game but might be helpful to u remove if not needed I dont know why roblox doesnt recognizxe the top half as code
for i, itemstats in pairs(inventorystats:GetChildren()) do
if itemstats.Value == “” then
itemstats.Value = “N/A”
print(itemstats.Name)
elseif itemstats.Name == "Shirt" and itemstats.Value == "" then
shirt.Value = "http://www.roblox.com/asset/?id=4789770554"
print(itemstats.Name)
elseif itemstats.Name == "Pants" and itemstats.Value == "" then
Pants.Value = "http://www.roblox.com/asset/?id=4789771258"
print(itemstats.Name)
end
end