The best way to search for the player from a server script?

Well, a part of the script that I did I did by mere chance but I really don’t know if it is efficient to search for the player in this way, the script is located inside a Folder within the player character. I would like to know if it is efficient, should I change it

local Players = game:GetService("Players")
player = script.Parent.Parent.Name
local LocalPlayer = Players:FindFirstChild(player)

The best way to get the LocalPlayer from a LocalScript is with simply LocalPlayer.

local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer

But I don’t mean a local script, but a server one

1 Like

Well it should work since player names are unique, but I would prefer doing something like this which uses the Instance function and the official function given in players service to get the player like so:

local Players = game:GetService("Players")

local character = script:FindFirstAncestorWhichIsA("Model")
local player = Players:GetPlayerFromCharacter(character)