Trouble With Saving a Simple Table

  1. What do you want to achieve? Keep it simple and clear!
    I want to save a table.

  2. What is the issue? Include screenshots / videos if possible!
    The table doesn’t save.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I looked on the Developer Hub but found nothing similar to my problem.

Here’s the script (it’s placed in ServerScriptService):


If someone could tell me how to

The first parameter of SetAsync is the key to save the value to, flip plr.UserId and tablee around

1 Like

you are the first person I have seen that unironically uses comic sans as a theme. so congrats? The main issue I see though is you mistyped the setasync function. The userid goes first and then the key.

3 Likes

I suggest instead of using Instance.new("INSTANCE_NAME", PARENT) you remove the PARENT variable inside the Instance.new() function. Then use the following script:

local Instance = Instance.new("INSTANCE_NAME")
-- Change other properties of the Instance here.
Instance.Parent = PARENT

As this is better performance wise, notice how you as well reparent the Instance to leaderstats after parenting it to the player.
You did not do it for the leaderstats though.

The script would look like this:

local DataStoreService = game:GetService("DataStoreService")
local store  = DataStoreService :GetDataStore("Datas")

game.Players.PlayerAdded:Connect(function(Player)
	local Leaderboard = Instance.new("Folder")
	Leaderboard.Name = "leaderstats"
	Leaderboard.Parent = Player

	local Coins = Instance.new("IntValue")
	Coins.Name = "Coins "
	Coins.Value = 0 -- Value beginners start with.
	Coins.Parent = Leaderboard
	
	local Clicks = Instance.new("IntValue", Leaderboard)
	Clicks.Name = "Clicks"
	Clicks.Value = 0 -- Default value
	Clicks.Parent = Leaderboard

	local data = KillsData:GetAsync(Player.UserId)
	if data then
		local Data = store:GetAsync(Player.UserId)
		if Data then
			Coins.Value = Data.Coins 
			Clicks.Value = Data.Clicks
		end
	end
end)

game.Players.PlayerRemoving:Connect(function(Player)
	KillsData:SetAsync(Player.UserId, {
		["Coins"] = Player.leaderstats.Coins.Value,
		["Clicks"] = Player.leaderstats.Clicks.Value,
	})
end)

Switch it around so it becomes "store:SetAsync(plr.UserId, tablee) also I would not recommend saving the actual stats of leaderboard