Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

why wont my currency work it wont show on leaderboard?

Asked by 2 years ago

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

0
Check to make sure that you are allowing http access and studio access to API. You can find these somewhere in the game settings I believe, but you may just have to google "enable studio access to api settings" to find out. cmgtotalyawesome 1418 — 2y
0
api services* cmgtotalyawesome 1418 — 2y
0
it is fixed k0lj0k0 0 — 2y

1 answer

Log in to vote
0
Answered by 2 years ago

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!

0
The script works, but you cannot get the Players.LocalPlayers from a Server script. Sarturex857 109 — 2y
Ad

Answer this question