Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Way's to define a Player?

Asked by
KenzaXI 166
9 years ago

I only 2 ways, local Player = game.Players.LocalPlayer and local Player = Brick.Parent:findfirstChild("Humanoid") Can you guys tell em any more ways? Thanks.

0
A Humanoid is not a Player. 1waffle1 2908 — 9y

2 answers

Log in to vote
1
Answered by
MunimR 125
9 years ago

There are several ways to get the Player from the client or server

Client side

First and most common method is:

game:GetService'Players'.LocalPlayer

The other way is to do:

game.Players.LocalPlayer

But this method is deprecated, so you shouldn't do it this way

Server side

The easy way to access a player is:

game:GetService'Players':FindFirstChild(PlayerName)

But make sure to have an if statement checking if the player exists

Another way is to do:

game:GetService'Players'[PlayerName]

A way to access a player from character is to do:

game:GetService'Players':GetPlayerFromCharacter(workspace.PlayerName)

This also works on client side, but more commonly used server side

Ad
Log in to vote
0
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
9 years ago

game.Players.LocalPlayer is for accessing the player of the client the script is running on.

GetPlayerFromCharacter will return a player given their character.

Answer this question