Datastore not working




local datastoreservice = game:GetService("DataStoreService")
local store = datastoreservice:GetDataStore("data")

game.Players.PlayerAdded:Connect(function(player)
	local id = player.UserId

	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	myvalues["intvalue"] = Instance.new("IntValue")
	myvalues["intvalue"].Parent = leaderstats
	local success,ttable = pcall(function()
		return store:GetAsync(id) 
	end)

	if success then
		for i,v in pairs(myvalues) do
			if type(v) == "number" then
			v.Value = ttable and ttable[i] and ttable[i].Value or 0
			elseif type(v) == "string" then
				v.Value = ttable and ttable[i] and ttable[i].Value or ""
			end
		end
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
	local id = player.UserId

	local success,error = pcall(function()
		store:SetAsync(id,myvalues)
	end)
end)

no errors at all

If you could tell us what specific issue you’re having and what you’re trying to achieve, that would be helpful :slight_smile:

Are you testing this is studio? If yes, then try testing it in a real game!