PcoWSkbVqDnWTu_dm2ix
The Developer Hub is now deprecated and information on this page may no longer be accurate. To see our new and improved documentation, please click here. You can read more about the future of documentation here.
Collapse Sidebar

GetPlayerFromCharacter

This function returns the Player associated with the given Player/Character, or nil if one cannot be found. It is equivalent to the following function:

local function getPlayerFromCharacter(character)
	for _, player in pairs(game:GetService("Players"):GetPlayers()) do
		if player.Character == character then
			return player
		end
	end
end

This method is often used when some event in player’s character fires (such as their Humanoid Humanoid/Died|dying). Such an event might not directly reference the Player object, but this method provides easy access. The inverse of this function can be described as getting the Character of a Player. To do this, simply access the Character property.

Parameters

Name Type Default Description

A character instance that you want to get the player from.

Returns

Return Type Summary

Code Samples


Playing in Third Person

This example demonstrates how to change the character’s CameraMode to third person using the Classic value of the Enum/CameraMode enum.


Players:GetPlayerFromCharacter