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

For i,v in pairs for a Fire script not working? (attempt to get length of v)

Hi, I have recently been trying to create a script where fires cannot be cloned in a part or object non stop, and this script does that. However, I only want one fire object to be present in the part, not hundreds of them which I use another cloning script for.

This is my code:

while wait() do
	for i, v in pairs (script.Parent:GetChildren()) do
		if v then
			if v.Name == "Fire" then
				for i = 1, (#v -1) do --Error line
				v:Destroy()
				wait()
				
			end
	
			end
			else return 
		end
	end
end

Line 5 seems to be the error in the output. This is what is printed in the output: Workspace.DanielRocky.HumanoidRootPart.OneFireOnly:5: attempt to get length of local 'v' (a userdata value)>

Help please?

1 comment

0

You attempted to get the length of a userdata (Instance). Instances have no length.

1 answer

while wait() do
local fireObjects = {} -- Creates empty tabled called "fireObjects"
    for i, v in pairs (script.Parent:GetChildren()) do
        if v then
            if v.Name == "Fire" then
		table.Insert(fireObjects, v) -- Inserts all of the "Fire" objects that are in Humanoid RootPart into the fireObjects table.
                for i = 1, (#fireObjects -1) do --This instead gets how many objects that are in the table.
                v:Destroy()
                wait()

            end

            end
            else return 
        end
    end
end

Hope this helps!

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