Hi, I was reading through the Health Pick Up tutorial on the Roblox Wiki and I'm having trouble understanding it. Here's the code I'm looking at.
local healthPack = script.Parent local function handleTouch(otherPart) local character = otherPart.Parent local humanoid = character:FindFirstChild('Humanoid') if humanoid then print('We should heal!') end end
So on line 3 they put the reference in for the function, then in line 4 they put "local character = otherPart.Parent" so the parent of a reference for a function is always the player? If not then how do you tell what the parent is for a reference? Any help is appreciated.
The function handleTouch is called when the healthpack is touched:
healthpack.Touched:connect(handleTouch)
The Touched event automatically returns the part that touched it. In the function handleTouch, that part is stored as the variable otherPart. So, if a character's right arm touched the health pack, otherPart would be
workspace.CharacterName["Right Arm"]
The parent of Right Arm is CharacterName.