I was making an autosave/autoload thing to my place. It saves leaderstats. Unfortunately, it doesn't work.The stats don't load. Here are my scripts:
Leaderstats/autoload:
local datastore = game:GetService("DataStoreService"):GetDataStore("AlienData")
game.Players.PlayerAdded:connect(function(player)
local leaderstats = Instance.new("IntValue")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local wins = Instance.new("IntValue")
wins.Name = "Wins"
wins.Parent = leaderstats
-- GUN RANK
local points = Instance.new("IntValue")
points.Name = "Points"
points.Parent = leaderstats
local key = "player_"..player.userId
local savedvalues = datastore:GetAsync("key")
if savedvalues then
wins.value = savedvalues[1]
points.Value = savedvalues[2]
else
local valuestosave = {wins.Value, points.Value}
datastore:SetAsync(key, valuestosave)
end
end)
Here is the onplayerleaving/autosave:
local datastore = game:GetService("DataStoreService"):GetDataStore("AlienData")
game.Players.PlayerRemoving:connect(function(player)
local key = "player_"..player.userId
local valuestosave = {player.leaderstats.Wins.Value, player.leaderstats.Points.Value}
datastore:SetAsync(key, valuestosave)
end)

1 comment
You have Value on line 25 in your loading script lower-case. Capitalize Value and try it.