I've posted about a not-working data store before, and someone helped me fix it. The problem is, it only worked once, and doesn't work anymore on anyone.

local DSService = game:GetService('DataStoreService'):GetDataStore('FakeDataStoreName')
game.Players.PlayerAdded:Connect(function(plr)
	-- Define variables
	local uniquekey = 'id-'..plr.UserId
	local leaderstats = Instance.new('IntValue', plr)
	local savevalue =  Instance.new('IntValue')
	leaderstats.Name = 'leaderstats'
	savevalue.Parent = leaderstats
	savevalue.Name = 'Clicks'
	
	-- GetAsync
	local GetSaved = DSService:GetAsync(uniquekey)
	if GetSaved then
		savevalue.Value = GetSaved[1]
	else
		local NumbersForSaving = {savevalue.Value}
		DSService:SetAsync(uniquekey, NumbersForSaving)
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
local uniquekey = 'id-'..plr.UserId
local Savetable = {plr.leaderstats.Clicks.Value}
DSService:SetAsync(uniquekey, Savetable)	
	
	
end)

It's in a Script in Workspace. What's wrong? The name of the Data Store, where "FakeDataStoreName" is, is 37 characters long, if that means anything. Please help me out!

2 comments

0

Use a pcall() on SetAsync() and GetAsync(). It's recommended to always wrap your DataStores in a pcall().

0

Don't come on this site with alvinbloxx's code, expecting for it to be fixed.