Hello

I know how to make a datastore script to save 1 value but i want to save 2 and its not working for me

Scrpit

--// Money DataStore Script
--// Made By XxLavaStoneexX

--// Var
local DataStore = game:GetService("DataStoreService"):GetDataStore("SaveMoney")

game.Players.PlayerAdded:Connect(function(plr)
	local Stats = Instance.new("IntValue",plr)
	Stats.Name = "leaderstats"
	local Cash = Instance.new("IntValue", Stats)
	Cash.Value = 0 --// Money The Player Starts With
	Cash.Name = "Cash" --// The Money Value Name
	local Wins = Instance.new("IntValue", Stats)
	Wins.Value = 0
	Wins.Name = "Wins"
	
	--// Get Saved Data
	local key = "id-"..plr.userId
	local GetSavedMoney = DataStore:GetAsync(key)
	if GetSavedMoney then
		Cash.Value = GetSavedMoney[1]
		Wins.Value  = GetSavedMoney[2]
	else
		local SaveMoneyUGotNow = {Cash.Value}
		local SaveWins = {Wins.Value}
		DataStore:SetAsync(key, SaveMoneyUGotNow, SaveWins)
	end
end)

--// Auto Save Money When The Player Leaves The Server

game.Players.PlayerRemoving:Connect(function(plr)
	local key = "id-"..plr.userId
	local AutoSaveMoney = {plr.leaderstats.Cash.Value}
	local AutoSaveWins = {plr.leaderstats.Wins.Value}
	DataStore:SetAsync(key, AutoSaveMoney, AutoSaveWins)
end)

1 comment

0

Dude, I sent a working script. Get out of here