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

How do I use in pairs to scan through a model with a humanoid it hits?

Asked by 6 years ago

What I am attempting to do here is clone a fire particle into any humanoid figure it touches.

For example, a zombies right leg hits the flames and the particle gets cloned into the leg then damages it over time and eventually goes away.

I'm still learning in pairs

local particle = script.Parent.clonefire
local particleclone = particle:Clone()

script.Parent.Touched:Connect(function(hit)
    for i,v in pairs(hit:GetChildren()) do
        if v:IsA("BasePart") and v.Name ~= "HumanoidRootPart" then
            particleclone.Parent = hit
        end
    end
end)
0
so it works? TheluaBanana 946 — 6y
0
yey TheluaBanana 946 — 6y
0
wdym LoganboyInCO 150 — 6y
0
^ He's being a bit.... echgh turtle2004 167 — 6y
0
o TheluaBanana 946 — 6y

1 answer

Log in to vote
1
Answered by 6 years ago

You have the right code, it's just that you are trying to scan through objects that are descendants... of an object. To get the players Character, first of all you need to use hit.Parent, as hit returns the part that touched it.

However it seems that you want to clone it into the part that touches, so all you need to do is use a conditional if statement to check if there are already particles in the leg, and if not then clone them into it.

local particle = script.Parent.clonefire
local particleclone = particle:Clone()

script.Parent.Touched:Connect(function(hit)
    for i,v in pairs(hit.Parent:GetChildren()) do
        if v:IsA("BasePart") and v.Name ~= "HumanoidRootPart" and not v:FindFirstChild("clonefire") then
            particleclone.Parent = hit
        end
    end
end)
0
I may have left something out so please do point it out if I have turtle2004 167 — 6y
0
I also need to disable two scripts in the particle, and another minor issue is when the particle gets cloned into the players limbs it quickly disappears after. LoganboyInCO 150 — 6y
0
you dont need to check if the instance's name is not equal to HumanoidRootPart User#23365 30 — 6y
0
v ~= hit.Parent.HumanoidRootPart User#23365 30 — 6y
0
wdym LoganboyInCO 150 — 6y
Ad

Answer this question