Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why does this script not save BoolValues?

Asked by 5 years ago

So i have made this script thats suposed to save the players Cash and the vehicles it has purchased, tho for some reason the vehicles purchased dont get saved only the Cashvalue.

Script:

local DataStore = game:GetService("DataStoreService") local ds1 = DataStore:GetDataStore("RTPD")

game.Players.PlayerAdded:connect(function(player) local leader = Instance.new("Folder", player) leader.Name = "leaderstats"

local Cash = Instance.new("IntValue", leader)
Cash.Name = "Cash"

Cash.Value = ds1:GetAsync(player.UserId) or 0
ds1:SetAsync(player.UserId, Cash.Value)

game.StarterGui.PurchaseGUI.Frame.Zilko_Natalia.Purchased.Value = ds1:GetAsync(player.UserId) or false

game.StarterGui.PurchaseGUI.Frame.Voyage_D.Purchased.Value = ds1:GetAsync(player.UserId) or false

game.StarterGui.PurchaseGUI.Frame.DA_Ferra.Purchased.Value = ds1:GetAsync(player.UserId) or false

game.StarterGui.PurchaseGUI.Frame.DA_Venerra.Purchased.Value = ds1:GetAsync(player.UserId) or false

game.StarterGui.PurchaseGUI.Frame.Hektor_Mediona.Purchased.Value = ds1:GetAsync(player.UserId) or false

game.StarterGui.PurchaseGUI.Frame.Mounts_Rake.Purchased.Value = ds1:GetAsync(player.UserId) or false

game.StarterGui.PurchaseGUI.Frame.Novena_Acesera.Purchased.Value = ds1:GetAsync(player.UserId) or false

game.StarterGui.PurchaseGUI.Frame.Roland_Motors_GTR.Purchased.Value = ds1:GetAsync(player.UserId) or false

game.StarterGui.PurchaseGUI.Frame.Surge_Maple_R.Purchased.Value = ds1:GetAsync(player.UserId) or false

game.StarterGui.PurchaseGUI.Frame.Voyage_Jalanster_Betamobili.Purchased.Value = ds1:GetAsync(player.UserId) or false

game.StarterGui.PurchaseGUI.Frame.Voyage_Pengangkuter_30_CWT.Purchased.Value = ds1:GetAsync(player.UserId) or false

wait(5)
--Cash.Changed:connect(function()
    print("SavingData")
    ds1:SetAsync(game.StarterGui.PurchaseGUI.Frame.Zilko_Natalia.Purchased.Value)
    ds1:SetAsync(game.StarterGui.PurchaseGUI.Frame.Voyage_D.Purchased.Value)
    ds1:SetAsync(game.StarterGui.PurchaseGUI.Frame.DA_Ferra.Purchased.Value)
    ds1:SetAsync(game.StarterGui.PurchaseGUI.Frame.DA_Venerra.Purchased.Value)
    ds1:SetAsync(game.StarterGui.PurchaseGUI.Frame.Hektor_Mediona.Purchased.Value)
    ds1:SetAsync(game.StarterGui.PurchaseGUI.Frame.Mounts_Rake.Purchased.Value)
    ds1:SetAsync(game.StarterGui.PurchaseGUI.Frame.Novena_Acesera.Purchased.Value)
    ds1:SetAsync(game.StarterGui.PurchaseGUI.Frame.Roland_Motors_GTR.Purchased.Value)
    ds1:SetAsync(game.StarterGui.PurchaseGUI.Frame.Surge_Maple_R.Purchased.Value)
    ds1:SetAsync(game.StarterGui.PurchaseGUI.Frame.Voyage_Jalanster_Betamobili.Purchased.Value)
    ds1:SetAsync(game.StarterGui.PurchaseGUI.Frame.Voyage_Pengangkuter_30_CWT.Purchased.Value)


    ds1:SetAsync(player.UserId, Cash.Value)
end)

--end)

game.Players.PlayerRemoving:connect(function(player) ds1:setAsync(player.UserId, player.leaderstats.Cash.Value)

ds1:SetAsync(game.StarterGui.PurchaseGUI.Frame.Zilko_Natalia.Purchased.Value)
ds1:SetAsync(game.StarterGui.PurchaseGUI.Frame.Voyage_D.Purchased.Value)
ds1:SetAsync(game.StarterGui.PurchaseGUI.Frame.DA_Ferra.Purchased.Value)
ds1:SetAsync(game.StarterGui.PurchaseGUI.Frame.DA_Venerra.Purchased.Value)
ds1:SetAsync(game.StarterGui.PurchaseGUI.Frame.Hektor_Mediona.Purchased.Value)
ds1:SetAsync(game.StarterGui.PurchaseGUI.Frame.Mounts_Rake.Purchased.Value)
ds1:SetAsync(game.StarterGui.PurchaseGUI.Frame.Novena_Acesera.Purchased.Value)
ds1:SetAsync(game.StarterGui.PurchaseGUI.Frame.Roland_Motors_GTR.Purchased.Value)
ds1:SetAsync(game.StarterGui.PurchaseGUI.Frame.Surge_Maple_R.Purchased.Value)
ds1:SetAsync(game.StarterGui.PurchaseGUI.Frame.Voyage_Jalanster_Betamobili.Purchased.Value)
ds1:SetAsync(game.StarterGui.PurchaseGUI.Frame.Voyage_Pengangkuter_30_CWT.Purchased.Value)

end)

0
Any errors? Torren_Mr 334 — 5y
0
there are no errors DaggerSaber 14 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

in the PlayerRemoving part you need to add

--at the top
local SavedData = instance.new("BindableEvent")

--At the end

SavedData:Fire()

game:BindToClose(function()
    SavedData.Event:Wait()
end)

and you forget to put a key. instead of player.UserId do player.UserId.."Cash" for cash and player.UserdId.."Purchased_[carname]" eg

DS1:SetAsync(**The long line**, player.UserdId.."Purchased_**the name of the car**"

Because if you are the last player if you leave the server will shut down so DataStore has no time to save it. What game:BindToClose does, if the server shuts down it will call the function until the function ends, the function ends when the data saved succesfully

0
You also want to wrap the saving in a pcall so if there is a error it wont break the script Luka_Gaming07 534 — 5y
0
Thank you for the answer but this did not fix my problem the cash did save but the BoolValues dont save at all [every place where you see "Purchased.Value" its a boolValue] DaggerSaber 14 — 5y
0
But keep that tho Luka_Gaming07 534 — 5y
0
You did not put a key for setAsync, and you should keep that other stuff from the answer Luka_Gaming07 534 — 5y
View all comments (11 more)
0
i edited the asnwer Luka_Gaming07 534 — 5y
0
so should i replace the long lines with the car names in them with player.UserdId.."Purchased_[carname]"? DaggerSaber 14 — 5y
0
ds1:SetAsync(game.StarterGui.PurchaseGUI.Frame.Zilko_Natalia.Purchased.Value, player.UserId.."Purchased_[carname]) that is what you need to do Luka_Gaming07 534 — 5y
0
ok thanks DaggerSaber 14 — 5y
0
if it works accept the answer Luka_Gaming07 534 — 5y
0
well it dosent work DaggerSaber 14 — 5y
0
Try going to Roblox wiki for help Luka_Gaming07 534 — 5y
0
ok DaggerSaber 14 — 5y
0
also how do i wrap the script in a PCall? DaggerSaber 14 — 5y
0
at the beginning of script type local success, err = pcall(function) at the end end) Luka_Gaming07 534 — 5y
0
thanks but that still didnt fix it DaggerSaber 14 — 5y
Ad

Answer this question