so i made a script that is supposed to save players cash, furnace multiplier, and bdb which is a number value, too lazy to explain what it does now.

heres the script:

local datastore = game:GetService("DataStoreService")
local ds1 = datastore:GetDataStore("DS23")
game.Players.PlayerAdded:Connect(function(plr)
	local cash = game.ServerStorage.MoneyStorage:WaitForChild(plr.Name)
	local bdb = plr:WaitForChild("bdb")
	local furnace = game.Workspace.Tycoon.Furnace1
	local success,err = pcall(function()
		cash.Value = ds1:GetAsync(plr.UserId) or 0
		bdb.Value = ds1:GetAsync(plr.UserId) or 0
		furnace.Multiplier.Value = ds1:GetAsync(plr.UserId) or 1
	end)
	if success then
		print("Your Data Has Been Loaded.")
	else
		print("Your Data Loading Has Failed.")
		warn(err)
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	local cash = game.ServerStorage.MoneyStorage:FindFirstChild(plr.Name)
	local furnace = game.Workspace.Tycoon.Furnace1
	local bdb = plr:WaitForChild("bdb")
	local success,err = pcall(function()
		ds1:SetAsync(plr.UserId, cash.Value)
		ds1:SetAsync(plr.UserId, furnace.Multiplier.Value)
		ds1:SetAsync(plr.UserId, bdb.Value)
	end)
	if success then
		print("Your Data Has Been Saved.")
	else
		print("We Got An Error While Saving Your Data.")
		warn(err)
	end
end)

I am having multiple issues:

  1. it doesnt save cash
  2. it doesnt save multiplier, when player joins for first time sometimes sets it to 0
  3. sometimes sets bdb to 1 for no reason?

any help will be appreciated since i was having issues with saving data in this game for few past weeks.

2 comments

0

you arent saving it from the leaderstats you are saving the blank value instead of the players version of the value

0

it worked before, it broke when i added furnace and bdb