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

What is the function's parameter's parent?

I am having trouble understanding what "hit"s parent is.

function Touched(hit)
	local kill = hit.Parent
	local humanoid = kill:FindFirstChildWhichIsA("Humanoid")
	if humanoid then
		humanoid.Health = 0
	end
end

script.Parent.Touched:Connect(Touched)

1 answer

✓ Accepted answer

The function :Touched() returns the OBJECT that touched the part. However, it doesn't returns a MODEL. So when a player's character touches the part, the :Touched() function will return a PART of the character. It will not return in character, because the character is a model. At the line 2 of the script you have wrote gets the player's character into a variable (the hit part's parent). But we don't know if the hit part's parent is a character of a player. Since every player's character has a child named humanoid, we can find out if it's a player's character or not. At line 3 you got the child named "humanoid" of the character into a variable. Then, at line 4, you used a if statement that verifies if the variable at line 3 EXISTS. If it exists, it's a player's character. Then, at line 5 you set the humanoid's health to 0. Hope this helped!

1 comment

0

I just started scripting and I think I fully understand this now!!!

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