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

Hey guys, it isnt saving anything. can anyone help me?

local ds = game:GetService("DataStoreService")
local cs = ds:GetDataStore("Cash")

game.Players.PlayerAdded:Connect(function(plr)
	local Cash = plr:WaitForChild("leaderstats"):WaitForChild("Cash")
	
	local data
	local succ, err = pcall(function()
		data = cs:GetAsync(plr.UserId.."_cash", Cash)
		
		if succ then
			Cash = data
			print("a")
		end
	end)
end)

game.Players.PlayerRemoving:Connect(function(plr)
	local data = plr.leaderstats.Cash.Value
	
	local succ, err = pcall(function()
		cs:SetAsync(plr.UserId.."_cash", data)
		
		if succ then
			print("it worked")
		else
			warn(err)
		end
	end)
end)

please help! it says

nil

when i leave which means nothing or there was an error

2 comments

0

Replace it with this:

0

Replace it with this:                                                                                                                         local Players = game:GetService("Players") local DataStoreService = game:GetService("DataStoreService") local Saver = DataStoreService:GetDataStore("SaveLeaderstats")

Players.PlayerAdded:Connect(function(player) local Data = nil local success, errormessag

1 answer

✓ Accepted answer

Please use nice words and not ''Guys'' I personally can't stand this. Try to put value behind Cash.

Cash.Value = 0

I see you did this at line 19, try to do this at line 5, 9 and 12 too.

Reply if it doesn't work!

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