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)