local DataStore = game:GetService("DataStoreService")
local PointsData = DataStore:GetOrderedDataStore("Points")
game.Players.PlayerAdded:Connect(function(plr)
local points = PointsData:GetAsync(plr.UserId)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
local pointsValue = Instance.new("IntValue",leaderstats)
pointsValue.Value = points
leaderstats.Parent = plr
end)
COMMUNITY QUESTION
leaderstats are nor working?
2 answers
Well, if you don't provide enough information for us, it will force us to moderate your question as 'Non-Descriptive'. But, I can help you fix various flaws in your code. Thanks to @Feelings_La for providing most of the fixed code. Here's what your code should look like, and explanation given in it :
local DataStore = game:GetService("DataStoreService")
local PointsData = DataStore:GetOrderedDataStore("Points")
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = plr
local pointsValue = Instance.new("IntValue")
pointsValue.Name = "Points" -- You forgot to name your value
pointsValue.Parent = leaderstats
local data -- Creating a nil variable
pcall(function() -- pcall is used to wrap the errors, and make the code to be able to executed further
data = PointsData:GetAsync(plr.UserId) -- Assigns our data variable to our data
end)
-- Now there can be two results of the data. First, it can be 'nil', which means that the data of the player is never saved, or the player has joined for the first time. Second, it can have some value that we can set it to our leaderstats value.
if data ~= nil then -- If the player joined is not a new player
pointsValue.Value = data
else -- If the player joined is a new player
pointsValue.Value = 0 -- Makes the value to 0, as for new players
end
end)
Again, thanks to @Feelings_La for saving my time.
Lemme know if it helps!
Do pointsValue.Parent = leaderstats instead of Instance.new("IntValue", leaderstats) because it is not recommended
local DataStore = game:GetService("DataStoreService")
local PointsData = DataStore:GetOrderedDataStore("Points")
game.Players.PlayerAdded:Connect(function(plr)
local points = PointsData:GetAsync(plr.UserId)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = plr
local pointsValue = Instance.new("IntValue")
pointsValue.Value = points
pointsValue.Parent = leaderstats
end)
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
whats wrong?