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

What is the role that the parameter "part" plays here?

Asked by 9 years ago

I don't understand it's role in this code, plz help meh :3. Thx gais. Btw its a kill script...

function die(part)
    h = part.Parent:FindFirstChild("Humanoid")
    if h~= nil then 
        h.Health = 0
    end
end

script.Parent.Touched:connect(die)

2 answers

Log in to vote
2
Answered by
duckwit 1404 Moderation Voter
9 years ago

The role of the parameter part here is to act as a reference to the output of the Touched event on BasePart.

According to the Official ROBLOX Wiki page about BasePart, the Touched event returns a reference of type Instance to the object that came into contact with the 'host' Part.

It is possible to ignore the values passed by an event, for example:

function Touch()  --There are no parameters, so the touched Part reference is 'dropped'
   print("Nothing Special")
end

script.Parent.Touched:connect(Touch)

The purpose of a parameter, in this case, is to provide a reference to a Part Instance.

Ad
Log in to vote
0
Answered by 9 years ago

Part is the part that touches the object, and the 2nd line is basically checking if the part has a humanoid.

Answer this question