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

the DataStore I added isn't saving my data. Can you tell me where have I gone wrong?

Here are my scripts. If you find any errors can you correct them in the answers? Thanks leaderstats script- game.Players.PlayerAdded:Connect(function(player) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player

local cash = Instance.new("IntValue")
cash.Name ="Cash"
cash.Value = 0
cash.Parent = leaderstats

end) DataStore script- local ds = game:GetService("DataStoreService"):GetDataStore("SaveData") game.Players.PlayerAdded:Connect(function(plr) wait() local plrkey = "id_"..plr.userId local save1 = plr.leaderstats.Cash

local GetSaved = ds:GetAsync(plrkey)
if GetSaved then
	save1.Value = GetSaved[1]
else
	local NumberForSaving = {save1.Value}
	ds:GetAsync(plrkey,NumberForSaving)
end

end)

game.Players.PlayerRemoving:Connect(function(plr) ds:SetAsync("id_"..plr.userId,{plr.leaderstats.Cash.Value}) end)

1 answer

Try this script and let me know does it work!

local players = game:GetService("Players")
local ds=game:GetService("CashSave")


players.PlayerAdded:connect(function(player)
	local folder = Instance.new("Folder")
	folder.Name = "leaderstats"
	folder.Parent = player

	local currency1 = Instance.new("IntValue")
	currency1.Name = "Cash"
	currency1.Parent = player.leaderstats
	currency1.Value = ds:GetAsync(player.UserId) or 0
	ds:SetAsync(player.UserId, currency1.Value)
		
	currency1.Changed:connect(function()
		ds:SetAsync(player.UserId, currency1.Value)
	end)

end)

2 comments

0

No it doesn't work

0

What error are you experiencing and is this placed in workspace or ServerScriptService?

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