Today I have enabled the API service on my Roblox game settings and created a leaderboard to show how many coins I gave on my game.
This is my script. It is a regular script placed in Serverscriptservice.
local dataStoreService = game:GetService("DataStoreService")
local dataStore = dataStoreService:GetDataStore("Coins")
game.Players.PlayerAdded:Connect(function(player)
local leaderboard = Instance.new("Folder",player)
leaderboard.Name = "Leaderboard"
local coins = Instance.new("IntValue",leaderboard)
coins.Name = "Coins"
coins.Value = 25
local recieved,failed = pcall(function()
data = dataStore:GetAsync("User-"..player.UserId)
end)
if recieved then
coins.Value = data[1]
print("Data was recieved")
else
print("Data was not recieved")
end
while true do wait(30)
dataStore:SetAsync("User-"..player.UserId,{coins.Value})
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local leaderboard = player.Leaderboard
local coins = leaderboard.Coins
local saved,failed = pcall(function()
dataStore:SetAsync("User-"..player.UserId,{coins.Value})
end)
if saved then
print("Data was saved")
else
print("Data was not saved")
end
end)
I checked the output and I got a message saying:
“Data was received”
I am pretty sure that the data had worked but my leaderboard still wasn’t showing up after enabling API because I made a print, making it say data was received if the data was received.
I really hope this can get solved/ find the issue because no one would want to collect coins without knowing how much they have.
I can not send any photos at this stage and this is the most I know about this issue/ script.
I hope I did not send this in the wrong category because I don’t know if this is a Roblox bug or if I am scripting something wrong.
Thank you for reading.