Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

why wont my currency work it wont show on leaderboard?

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

3 comments

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.

0

api services*

0

it is fixed

1 answer

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!

1 comment

0

The script works, but you cannot get the Players.LocalPlayers from a Server script.

This discussion is preserved as it was. New answers, comments, and votes are closed.