I don't understand this code:
local parent = part.Parent if game.Players:GetPlayerFromCharacter(parent)
I know what a parent is, I know if statements, but what does all this mean?
I don't understand this code:
local parent = part.Parent if game.Players:GetPlayerFromCharacter(parent)
I know what a parent is, I know if statements, but what does all this mean?
I take it this is inside a .Touched event function. What the script does is check if the part that triggered the touch event belongs to a player, and therefore can be used to run code only when a player touches something.
part refers to the block triggering the touched event. If this is a players arm, head, torso, etc., part.parent will then refer to the character (model group) in the workspace. This next function game.Players:GetPlayerFromCharacter(parent) will either return the corresponding player object in game.Players or nil, which will evaluate to true or false respectively in an if statement.
This discussion is preserved as it was. New answers, comments, and votes are closed.