Could someone explain what :GetPlayerFromCharacter() mean in plain English i am new to scripting however i know c++ and java please include examples and when someone would use this function
Thank you!
This answer's to be used as a reference
The GetPlayerFromCharacter
function's pretty self explanatory; it's a function that returns a player from their character. :p This can useful for certain things, such as checking whether a character is a player's. Here's example with the Touched
event;
Part.Touched:Connect(function(ObjThatHit) -- The touched event listens for when an object (or a part) touches it, and when it does it returns it. if ObjThatHit.Parent then -- Checks whether the object's parent was changed to false (this can happen with bullets). local IsPlayer = game.Players:GetPlayerFromCharacter(ObjThatHit.Parent) -- The variable to retrieve the player, if it was a player. print(IsPlayer and 'Is a player' or 'Isn\'t a player!') -- Prints whether what touched it was a player or not. end end)
Some things to note when using it;
1. It's a function of the Players
service, so you'll need to call it from it. Players:GetPlayerFromCharacter
2. It requires the model for the player, thus the GetPlayerFromCharacter(Model)
3. If it wasn't a player that was given to it, it'll return nil.
Stuff touched on
GetPlayerFromCharacter
- Returns a player if what was given to it was a player's character.Touched
- An event that listens for when something touches the part it's connected to.If you have any more questions, feel free to let me know. :) I hope this helped! :D