I don't understand how the code below works, I found it on the wiki. I thought you couldn't assign something to multiple things? Can someone please explain this???
local humanoid = hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") --Assigned to three different things???
It's not assigning a variable to three different things. Two of these are just checking if other things are there.
A code like this:
if hit.Parent then
just checks to make sure the parts parent is there. The same thing is happening with the other bit of code. Putting the code in like this pretty much is asking the game "does it exist?" The same thing goes with this code:
local humanoid = hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid")
It's just checking if each part is there or not, and if it is there, it removes it being assigned from the last part, and assigns it to the next part. So, the code would go like this:
humanoid = hit
If hit.Parent exists, then humanoid = hit.Parent, instead of hit
If hit.Parent:FindFirstChild("Humanoid") exists, then humanoid = hit.Parent:FindFirstChild("Humanoid"), instead of hit.Parent
If you want to test this out to see what I mean, try putting this script into a Part, and testing it:
script.Parent.Touched:connect(function(hit) local humanoid = hit print("Line 2: "..humanoid.Name) local humanoid2 = hit and hit.Parent print("Line 4: "..humanoid2.Name) local humanoid3 = hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") print("Line 6: "..humanoid3.Name) end)
It should print out each part separately to the output so you can get a visual of what I'm saying.
Anyways, I hope this cleared things up for you a bit, and I hope I helped. If you have any further questions or problems, please leave a comment below :P