Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does this script not save BoolValues?

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)

2 comments

0

Any errors?

0

there are no errors

1 answer

✓ Accepted answer

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

15 comments

0

You also want to wrap the saving in a pcall so if there is a error it wont break the script

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]

0

But keep that tho

0

You did not put a key for setAsync, and you should keep that other stuff from the answer

0

i edited the asnwer

0

so should i replace the long lines with the car names in them with player.UserdId.."Purchased_[carname]"?

0

ds1:SetAsync(game.StarterGui.PurchaseGUI.Frame.Zilko_Natalia.Purchased.Value, player.UserId.."Purchased_[carname]) that is what you need to do

0

ok thanks

0

if it works accept the answer

0

well it dosent work

0

Try going to Roblox wiki for help

0

ok

0

also how do i wrap the script in a PCall?

0

at the beginning of script type local success, err = pcall(function) at the end end)

0

thanks but that still didnt fix it

This discussion is preserved as it was. New answers, comments, and votes are closed.