:GetPlayerByUserId function returning nil

Hello DevFourm! I’m trying to make a test script testing a feature I am considering making a game on. I am testing a feature where you can enter a player’s name and it will return all the information (publicly) available about that player. My main goal is to get the players “Player” by their name. First I got the player’s userID from the “GetUserIdFromName” function. That worked out well. However, when I went to get the player’s name from their userid it returned nil for some reason.

Heres the script. (LocalScript):

local name = "Roblox"
local players = game:GetService("Players")
local userID = players:GetUserIdFromNameAsync(name)
local player = players:GetPlayerByUserId(userID)

print(player)

Thank You :slight_smile: (It returns nil in a server script too)

It’s returning nil because GetPlayerByUserId can only find players that are present within your game

3 Likes

Oh, okay! Thank you for letting me know :slight_smile:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.