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

Why won't my data store save correctly?

So I made a Data Store that saves both tools and money, but for some reason it doesn't work. The output doesn't show any errors so I got a dead end.

The Code:

local DSS = game:GetService("DataStoreService")
local MoneySave = DSS:GetDataStore("General", "Money")
local GearSave = DSS:GetDataStore("General", "Gear")

game.Players.PlayerAdded:Connect(function(player)
	local key = "player-".. player.UserId
	pcall(function()
		local money = MoneySave:GetAsync(key)
		local gear = GearSave:GetAsync(key)
		
		if money then
			player:WaitForChild("leaderstats"):WaitForChild("Money").Value = MoneySave[1]
		else
			local MoneyForSaving = {player:WaitForChild("leaderstats"):WaitForChild("Money").Value}
			MoneySave:GetAsync(key, MoneyForSaving)
		end
		
		if gear then
			for _,v in pairs(gear) do
				local gears = game:GetService("ReplicatedStorage"):FindFirstChild(v)
				if gears then
					gears:Clone().Parent = player.Backpack
					if not player.StarterGear:FindFirstChild(v) then
						gears:Clone().Parent = player.StarterGear
					end
				end
			end
		end
	end)
end)

game.Players.PlayerRemoving:Connect(function(player)
	local key = "player-".. player.UserId
	pcall(function()
		local MoneyToSave = {player:WaitForChild("leaderstats"):WaitForChild("Money").Value}
		local GearToSave = {}
		
		for _,v in pairs(player.Backpack) do
			table.insert(GearToSave, v.Name)
		end
	end)
end)

And please, tell me what I did wrong

2 comments

0

hey, I made a script like this. I found a solution. Here's the answer: https://scriptinghelpers.org/

1 answer

You're getting the data store, but I don't see you setting it anywhere. Look into SetAsync and UpdateAsync.

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