The GetPlayerFromCharacter
function "returns the Player
associated with the given character
, or nil
if the character
is not controlled by a player"
If you have a player's character model (the physical model), you can find the corresponding Player instance for that character (the object in the Players service which has GUIs and the StarterGear and PlayerPack).
The essential is that it "undoes" player.Character
, that is,
game.Players:GetPlayerFromCharacter( player.Character )
is player
.
Because it returns nil
(as opposed to erroring) you can also use this to determine if a given model is actually a ROBLOX player rather than something else in, for example, a Touched
event:
04 | local player = game.Players:GetPlayerFromCharacter(hit.Parent); |
06 | game.ReplicatedStorage.Weapon:Clone().Parent = player.PlayerPack; |
10 | somepart.Touched:connect(onTouch); |