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

Why is this displaying id number? [UNANSWERED]

Hi guys! This is an ordered datastore gui, and I am trying to make it compatible with name changing. Basically, I am now saving the id of the player so I can load their current name when they join.

However, although it is working, it is now displaying like so on the leaderboard:

  1. jjwood1600
  2. 4418264 (the id of the player)

Any ideas why it is doing this? Other than that it works fine. Thanks.

local ODS = game:GetService("DataStoreService"):GetOrderedDataStore("Escapes")
local pages = ODS:GetSortedAsync(false, 10)
local Count = 0
local Gui = script.Parent

function Leaderboard()
Count = 0
local data = pages:GetCurrentPage()    
for i,item in next, (data) do
Count = Count + 1
local Board = Gui:FindFirstChild("Place"..Count.."")
if type(item.key) == "number" then
name = game.Players:GetNameFromUserIdAsync(item.key)
Board.PName.Text = name
else
Board.PName.Text = item.key
end

Board.Score.Text = item.value
if Count == 10 then return end
end
end
Leaderboard()
function PlayerLeaving(Player)
	ODS:SetAsync(Player.userId, Player.leaderstats.Escapes.Value)
end

game.Players.PlayerRemoving:connect(PlayerLeaving)

1 answer

Your issue is probably with this line:

if type(item.key) == "number" then

The key, I'm guessing, is always a string. Sometimes, it's a string of numbers. Try changing that line and modifying the next:

if tonumber(item.key) then
name = game.Players:GetNameFromUserIdAsync(tonumber(item.key))

1 comment

0

I'll test it ASAP and let you know how it goes! :) Thanks!

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