Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Please help? I am a beginner and I don't understand what local parent = part.Parent means

Asked by 3 years ago

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?

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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.

Ad

Answer this question