Thanks for clarifying! If the leaderboard used to show "Coins: 0" but now it doesn’t show anything at all, that means the leaderstats folder or the Coins value is not being created or displayed properly.
Your script looks mostly correct, but there are a couple of things to improve to make sure it works reliably:
1. Use pcall for DataStore calls
DataStore calls can fail sometimes, so it’s best to wrap them in pcall to avoid errors that stop the script.
2. Make sure the NumberValue instances are parented correctly
You’re currently creating the NumberValue with the parent as the second argument, which works, but it’s better to create the instance first, then set its properties explicitly for clarity.
Here’s a revised version of your leaderstats script with these improvements:
lua
local DataStoreService = game:GetService("DataStoreService")
local coinsStore = DataStoreService:GetDataStore("CoinsStore")
local gemsStore = DataStoreService:GetDataStore("GemsStore")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local coins = Instance.new("NumberValue")
coins.Name = "Coins"
coins.Parent = leaderstats
local gems = Instance.new("NumberValue")
gems.Name = "Gems"
gems.Parent = leaderstats
-- Load coins safely
local success, coinsValue = pcall(function()
return coinsStore:GetAsync(player.UserId)
end)
if success and coinsValue then
coins.Value = coinsValue
else
coins.Value = 0
end
-- Load gems safely
local success2, gemsValue = pcall(function()
return gemsStore:GetAsync(player.UserId)
end)
if success2 and gemsValue then
gems.Value = gemsValue
else
gems.Value = 0
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local leaderstats = player:FindFirstChild("leaderstats")
if leaderstats then
local coins = leaderstats:FindFirstChild("Coins")
local gems = leaderstats:FindFirstChild("Gems")
if coins then
pcall(function()
coinsStore:SetAsync(player.UserId, coins.Value)
end)
end
if gems then
pcall(function()
gemsStore:SetAsync(player.UserId, gems.Value)
end)
end
end
end)
What to do next:
Replace your current leaderstats script with this one.
Run the game in Roblox Studio.
Check if the leaderboard shows Coins: 0 and Gems: 0 when a player joins.
If it still doesn’t show, check the Output window for any errors.
Extra tip:
If the leaderboard still doesn’t show, make sure no other script is deleting or interfering with the leaderstats folder or its children.
If you want, I can also help you add a simple way to give coins manually for testing, just let me know!