How to get a player? (from function)

Hello I am trying to Make a function getting the localplayer but I dont know how to!
I Cant seem to figure it out I would have to mess up my game to do it…
help would be Cool!

1 Like

This is kinda useless because you can just easily get it with game.Players.LocalPlayer But here it is

It works on both client and server, But make it client

Local script / Script ( RunContext > Client )

local function GetPlayer()
	return game:GetService("Players").LocalPlayer or game:GetService("Players"):FindFirstChildOfClass("Player")
end

Here is how you use it

local Player = GetPlayer()

print(Player.Name)
1 Like

You don’t actually need a “function” to find this, there is a built-in variable that luau provides, all you need to do is execute it.

local LocalPlayer = game.Players.LocalPlayer
1 Like

I wasn’t talking to you, I was talking to him because he said he doesn’t know how to summon the local player

If you’re doing it from the client it is very simple

local Player = game:GetService("Players").LocalPlayer
print("Yeah! We got "..Player.Name.."!")

From server side you could use:

game:GetService("Players").PlayerAdded:Connect(function(Player)
print("Yeah! We got "..Player.Name.."!")
end)

Or you could fire a remote event from client to server. There are multiple ways.

Just to let Y’all know, its a one player per server game.

In that case,

local Player = game:GetService("Players"):GetPlayers()[1]

This should give you the player, server or local side, in a one player game.

thanks I will get back to you.