Parameter Confusion

This is confusing to me, I was recently studying this script, and how the heck does this script know that “bagels” is a part touching the part?

local part = script.Parent

local function kill(Bagels)
	local bagelsParent = Bagels.Parent
	local humanoid = bagelsParent:FindFirstChild("Humanoid")
	if humanoid then
		humanoid.Health = 0
	end
end

part.Touched:Connect(kill)
1 Like

part.Touched is an event that will be triggered anytime another part touches it. When this happens, it will fire any connected functions and pass along the part that touched it. That’s what you’re seeing here. The kill function is hooked up to part.Touched. So when the part is touched and the event is fired, it passes the touched part to kill.

So it’s a bit hidden behind the scenes. Roblox takes care of the touch detection and firing the connected functions.

4 Likes

to add on to what sletnick said bagels is any instance being touched by the part bagelsParent
references the parent of the instance if the player makes contacts with the part all of the players parts are registered as instance which is what we want because they all share the same parent which is good next they create a variable for the humanoid which in this case they call it humanoid the if statement makes sure that humanoid contacts with the part actually happened to prevent miss fires or the players health being set to zero as the part touches non player instances next we kill the player with Health = 0 which sets their hp to zero in turn killing them so that pretty much sums up the code hope i helped

1 Like