the currency doesnt show on the leader board please help code is
local currencyname = "Coins" --Name of the currency local Datastore = game:GetService("DataStoreService"):GetDataStore("TestDataStore") --Stores The Amount
game.Players.PlayerAdded:Connect(function(player) --next few lines add the leaderboard data
local folder = Instance.new("Folder") folder.Name = "leaderstats" folder.Parent = player local currency = Instance.new("IntValue") currency.Name = CurrencyName --takes the name of your currency and adds it into the leaderboard currency.Parent = folder local ID = currencyName.."-"..player.UserId local savedData = nil pcall(function() savedData = DataStore:Async(ID) end) if savedData ~= nil then currency.Value = savedData print("Data Loaded") --Tells that data has loaded else -- If New Player Loads The Following currency.Value = 50 print("New Player To The Game") end
end)
game.Players.Removing:Connect(function(player) local ID = currencyName.."-"..player.UserId DataStore:SetAsync(Id,player.leaderstats [currencyName] .Value) end)
game:BindToClose(function()
--Starts when Server Shutsdown for i, player in pairs (game.Players:GetPlayers()) do if player then player:Kick("This Server Has Started To Shutdown. Please do rejoin") --the message it gives you end end wait(5) --waits 5 seconds so they can read the message then kicks them
end
Put the following code into SSS (Server Script Service)
game.Players.PlayerAdded:Connect(function(player) local folder = Instance.new("Folder") folder.Name = "leaderstats" folder.Parent = player local currency = Instance.new("IntValue") currency.Name = CurrencyName --takes the name of your currency and adds it into the leaderboard currency.Parent = folder
It was not working because you needed to run the code when the player joins the game. To do this simply add a
game.Players.PlayerAdded:Connect(function(player) --I suggest having the variable "player" there, as that will make it easier so you dont have to do game.Players.LocalPlayer.
Hope this helped!