Leaderstats not showing up

So, I tried to make a leaderstat for a cafe.
It seems like it doesn’t show up on the leaderstats, there are no errors in the console.
Here is the code:
local dataStoreService = game:GetService(“DataStoreService”)
local statStore = dataStoreService:GetDataStore(“StatStore”)

game.Players.PlayerAdded:Connect (function(player)
local leaderstats = Instance.new(“Folder”,player)
leaderstats.Name = “Points”
local points = Instance.new(“IntValue”,leaderstats)
points.Name = “Points” – Obvious.
points.Value = 0

local recived, notRecived = pcall(function()
	stat = statStore:GetAsync("UserID-"..player.UserID)
end)

if recived then
	points.Value = stat[1]
	print("Recived")
else
	print("Not recived")
end

while true do wait(30)
	statStore:SetAsync("UserID-"..player.UserId, {points.Value})
	print("AutoSaved")
end

end)

game.Players.PlayerRemoving:Connect(function(player)
local leaderstats = player.Leaderstats
local points = leaderstats.Points

local saved, notSaved = pcall(function()
	statStore:SetAsync("UserID-"..player.UserId, {points.Value})
end)

if saved then
	print("Saved!")
else
	print("Not saved!")
end

end)

The name of the container (the model or folder the stats are stored in) should be “leaderstats”:

leaderstats.Name = "leaderstats"

It is case-sensitive, so all characters have to be in lowercase. Also, don’t use the 2nd parameter of Instance.new - it leads to some performance issues. What you can do is omit the 2nd parameter and create the object, initialise the object (i.e set all of the properties) then parent it after. There is a PSA on it

4 Likes