print(target) -- prints
if game.Players:GetUserIdFromNameAsync(target) ~= nil then
print("Match") -- prints
print(game.Players:GetUserIdFromNameAsync(target)) -- prints correctly
local p = game.Players:GetPlayerByUserId(game.Players:GetUserIdFromNameAsync(target))
table.insert(sorted_a, p)
print(p.Name) -- attempt to index nil with 'Name'
found = true
end
If the player ur trying to get isn’t in the game, it returns nil. I suggest u use a roblox api to get the username of a player thats not in the current game
local playerName = “Diamond_Plus1”
local function getPlayerFromUserName(name)
for _, v in pairs(game.Players:GetPlayers()) do
if v.Name == name then
return v
end
end