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

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

Asked by 3 years ago
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)
0
hit.Parent is the player touched's character that touched the "script.Parent" Xapelize 2658 — 3y
0
in the Touched event Xapelize 2658 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

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.)

0
Thank you but how does hit.Parent identify the player? thecoolguy436 38 — 3y
0
There's a built-in function for that. game.Players:GetPlayerFromCharacter(hit.Parent) NotThatFamouss 605 — 3y
Ad

Answer this question