Can you guys tell me in a full explanation what this means? I looked on the Roblox Wiki and it still doesn't make sense to me. Thanks.
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:
-- Example touched event to give a player a weapon function onTouch(hit) if hit.Parent then local player = game.Players:GetPlayerFromCharacter(hit.Parent); if player then game.ReplicatedStorage.Weapon:Clone().Parent = player.PlayerPack; end end end somepart.Touched:connect(onTouch);