What do you want to achieve? Keep it simple and clear!
I want to save a table.
What is the issue? Include screenshots / videos if possible!
The table doesn’t save.
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):
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.
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)