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
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