i never had a way to get coins yet cuz im working on the game. but before, on the…
- User
i never had a way to get coins yet cuz im working on the game. but before, on the leaderboard it would say Coins: 0
- Assistant
Ah, got it! So the issue isn't that the coins stopped working, but rather:
The
Coinsvalue is no longer showing up in the leaderstats at all.And since you never had a system to earn coins yet, you're now seeing no Coins entry at all — whereas before, when you had pet/crafting systems, it might have been defaulting to 0.
Let's make sure your leaderstats script works perfectly and always shows
Coins: 0andGems: 0by default.
✅ Here's an improved version of your Leaderstats Script with:
- Proper error handling
- Auto-saving every few minutes (auto-save interval)
- Ensuring values are created even if DataStore fails
local DataStoreService = game:GetService("DataStoreService") local Players = game:GetService("Players") local COINS_STORE = DataStoreService:GetDataStore("CoinsStore") local GEMS_STORE = DataStoreService:GetDataStore("GemsStore") -- How often to auto-save player data (in seconds) - 5 minutes = 300s local AUTO_SAVE_INTERVAL = 300 -- Function to create leaderstats folder local function createLeaderstats(player) local folder = Instance.new("Folder") folder.Name = "leaderstats" folder.Parent = player local coinsValue = Instance.new("IntValue") coinsValue.Name = "Coins" coinsValue.Value = 0 coinsValue.Parent = folder local gemsValue = Instance.new("IntValue") gemsValue.Name = "Gems" gemsValue.Value = 0 gemsValue.Parent = folder -- Try loading saved data local success, coins = pcall(function() return COINS_STORE:GetAsync(player.UserId) end) if success and type(coins) == "number" then coinsValue.Value = coins end success, gems = pcall(function() return GEMS_STORE:GetAsync(player.UserId) end) if success and type(gems) == "number" then gemsValue.Value = gems end -- Auto save periodically spawn(function() while true do wait(AUTO_SAVE_INTERVAL) if not player:IsDescendantOf(game) then break end -- Player left pcall(function() COINS_STORE:SetAsync(player.UserId, coinsValue.Value) GEMS_STORE:SetAsync(player.UserId, gemsValue.Value) end) end end) end -- Save on leaving Players.PlayerRemoving:Connect(function(player) pcall(function() local leaderstats = player:WaitForChild("leaderstats") local coins = leaderstats.Coins local gems = leaderstats.Gems COINS_STORE:SetAsync(player.UserId, coins.Value) GEMS_STORE:SetAsync(player.UserId, gems.Value) end) end) -- Create leaderstats on join Players.PlayerAdded:Connect(function(player) createLeaderstats(player) end) -- Optional: Add leaderstats for players already in game for _, player in pairs(Players:GetPlayers()) do createLeaderstats(player) end
✅ What this script does:
- Always creates the
CoinsandGemsvalues as IntValue - Sets them to 0 by default
- Loads saved data from DataStore if available
- Saves data when player leaves
- Also auto-saves every 5 minutes (you can tweak this)
- Handles errors gracefully with
pcall
🧪 Test It Out:
- Paste this into your
ServerScriptService(replace your current script). - Run the game.
- Join the game and check if Coins: 0 appears in the leaderboard.
If it still doesn’t show up, let me know — we’ll debug together.
🔒 Want to add a way to earn coins later?
Once you’re ready, I can help you add:
- Coins for killing enemies
- Coins for collecting objects
- Shop system
- Coin animations or effects
Just say the word 😊
Would you like me to write a simple coin collector script too?
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.