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

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

Asked by 6 years ago

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?

0
You attempted to get the length of a userdata (Instance). Instances have no length. cabbler 1942 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
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!

Ad

Answer this question