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

I cant make the Model's children unancored. Is there something wrong with my for i,v in pairs loop?

Asked by 4 years ago
Edited 4 years ago

I'm trying to make the tree's leaves unancored when it chopped down. but leaves stays where it is. Is there something wrong with my for i,v in pairs loop?

Note: Wood is the part that i clicked. Tree Model structure: https://imgur.com/5yxO95I

    if Cursor.Target ~= nil and Cursor.Target.Parent.Name == 'Tree' and  Gather == true then
        local Wood = Cursor.Target
        if (Wood.Position - Char.HumanoidRootPart.Position).magnitude <10 then
            Gather = false
            RG = Player.PlayerGui.Gathering
            RG.BG.Visible = true
            Char.Humanoid.WalkSpeed = 0
            ShowProgress('Tree')
            Char.Humanoid.WalkSpeed = 16

            for i,v in pairs(Wood.Parent.Leaves:GetChildren()) do
                if v:IsA('Part') then
                    v.Anchored = false
                end
            end

            Wood:Destroy()
            --Drop Wood
            RG.BG.Visible = false
            Gather = true
        end
    end
0
Provide an image of the explorer, please. (Of the tree leaves' children.) Arj783 72 — 4y
0
Uh, are this is the full script, or there any errors? Xapelize 2658 — 4y
0
I don't think it's the loop. It could be the magnitude condition not passing. DeceptiveCaster 3761 — 4y
0
its only the error part emay0660 13 — 4y
0
I added tree model structure's photo as well emay0660 13 — 4y

1 answer

Log in to vote
0
Answered by
Y_VRN 246 Moderation Voter
4 years ago

I don't think you should put...

for i,v in pairs(Wood.Parent.Leaves:GetChildren()) do
    if v:IsA('Part') then
        v.Anchored = false
    end
end

Use...

local leaves = Wood.Parent.Leaves:GetChildren()

for i = 1, #leaves do
    if leaves[i]:IsA('BasePart') then -- I prefer using BasePart instead of just Part as it includes Unions.
        leaves[i].Anchored = false
    end
end
Ad

Answer this question