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

Why is my table value not being called properly?

So I have a simple script:

local part = script.Parent
local db = false

function burn(hit)
	local myArray = {}
	local p1 = hit.Parent:FindFirstChild("Left Arm")
	local p2 = hit.Parent:FindFirstChild("Right Arm")
	local p3 = hit.Parent:FindFirstChild("Left Leg")
	local p4 = hit.Parent:FindFirstChild("Right Leg")
	local p5 = hit.Parent:FindFirstChild("Torso")
	local fire = Instance.new("Fire")
	local human = hit.Parent:FindFirstChild("Humanoid")
	table.insert(myArray{p1, p2, p3, p4, p5})
	
	if human then
		if not db then
			
			db = true
			
			fire.Parent = #myArray
			end
		end
	end
	
part.Touched:connect(burn)

What it's supposed to do, is when I step on the part, ALL the body parts in myArray catch fire. But something is not working. Any ideas? All help is appreciated!

1 answer

✓ Accepted answer

You're going to have to create a loop and clone the Fire instance multiple times if you want to do this. Also, with how your table is set up, it can be visualized as something like this:

local myArray = { {p1,p2,p3,p4,p5} }

I've demonstrated how to fix both of these issues in the code below:

local part = script.Parent
local fire = Instance.new("Fire")
local db = false

function burn(hit)
	if hit.Parent then
		
		local p1 = hit.Parent:FindFirstChild("Left Arm")
		local p2 = hit.Parent:FindFirstChild("Right Arm")
		local p3 = hit.Parent:FindFirstChild("Left Leg")
		local p4 = hit.Parent:FindFirstChild("Right Leg")
		local p5 = hit.Parent:FindFirstChild("Torso")
		
		local human = hit.Parent:FindFirstChild("Humanoid")
		
		if human and p1 and p2 and p3 and p4 and p5 then
			
			local myArray = {p1, p2, p3, p4, p5}
			
			if not db then
				db = true
				
				for i,v in pairs(myArray) do
					fire:Clone().Parent = v
				end
			end
		end
	end
end

part.Touched:connect(burn)

If you have any more questions or it doesn't work, feel free to ask!

3 comments

0

Is it possible to make this with a "for i,v in pairs" loop? That'd work better. I don't like using things I don't understand.

0

Sure, I've edited my post.

0

You could just loop through everything in the character model and if the item is a basepart (and not the root part, if you want) then add the fire. Then you wouldn't need every limb in order for it to work.

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