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!
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;
Players service, so you'll need to call it from it. Players:GetPlayerFromCharacterGetPlayerFromCharacter(Model)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
This discussion is preserved as it was. New answers, comments, and votes are closed.
4 comments
still confused why would someone use this function and thank you for helping!
One use could be to check whether a NPC touched a shop brick. And yw. :) If this answered your question, do you mind accepting it please?
you use it when you don't have reference to the player but have reference to the character.
Tyvm for accepting! ^^