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

Will someone help me with the Roblox Wiki Health Pick up code?

Asked by 6 years ago

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.

1 answer

Log in to vote
0
Answered by 6 years ago

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.

0
Thank you so much! I really appreciate it! bretinat0r 4 — 6y
Ad

Answer this question