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

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

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)

5 comments

0

so it works?

0

yey

0

wdym

0

^ He's being a bit.... echgh

0

o

1 answer

✓ Accepted answer

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)

5 comments

0

I may have left something out so please do point it out if I have

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.

0

you dont need to check if the instance's name is not equal to HumanoidRootPart

0

v ~= hit.Parent.HumanoidRootPart

0

wdym

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