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

I was wondering why this guy did this like what is hits parent and how does it matter to the script?

script.Parent.Handle.Touched:Connect(function(hit)
	if db then
		if not canHit then
			canHit = true
			local effect = script.Parent.Handle.Effect:Clone()
			if hit.Parent:FindFirstChild("Humanoid") then
				local hitSFX = Instance.new("Sound",hit.Parent.Head); hitSFX.SoundId = "rbxassetid://566593606"; hitSFX:Play()
				hit.Parent.Humanoid:TakeDamage(25)
				if con.bloodEffects == true then
					effect.Parent = hit.Parent.HumanoidRootPart
					effect.Enabled = true
				end
			end
			wait(1)
			effect:Destroy()
			canHit = false
		end
	end
end)

2 comments

0

hit.Parent is the player touched's character that touched the "script.Parent"

0

in the Touched event

1 answer

✓ Accepted answer

It is used to identify the object that touched the instances. In this case, we're using it to identify humanoids.

hit.Parent:FindFirstChild("Humanoid")

The script was told to find a child named "Humanoid". It's using a .Parent because the one that's hitting it is gonna be the character's limb. So hit.Parent is used to identify the Character.

If you do this without specifying hit, you're giving yourself a hard job; let's say I want to make a killing part, I will need to get the Character's humanoid that hit the part, right? You don't want to specify it yourself. Especially using a specified variable for it.

That's where the hit comes in handy.

script.Parent.Touched:Connect(function(hit)
	local Humanoid = hit.Parent:FindFirstChild("Humanoid")
	
	if Humanoid then
		Humanoid.Health = 0
	end
end)

It defines hit as the limb/part that hits it. Then it finds the Character's Humanoid with hit.Parent:FIndFirstChild(). It then checks if Humanoid is not nil. In this case, it found the Humanoid, executing the rest of the script.

(I'm sorry if this comes off unclear, inform me and I'll try to rewrite it if it's not clear enough.)

2 comments

0

Thank you but how does hit.Parent identify the player?

0

There's a built-in function for that. game.Players:GetPlayerFromCharacter(hit.Parent)

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