Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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.

1 comment

0

Thank you so much! I really appreciate it!

This discussion is preserved as it was. New answers, comments, and votes are closed.