I’m attempting to make a script where it finds a random part and deletes it’s welds. The issue is, it states that Weld is not a valid member, even though it does exist. I tried to put a WaitForChild, but it infinite yielded. Other posts weren’t relevant or didn’t work. Any help is appreciated!
local Model = workspace.Grassland
local function DeleteRandomPart()
local ChildrenOfModel = Model:GetChildren()
local PartToDelete = ChildrenOfModel[math.random(#ChildrenOfModel)]
local Weld = PartToDelete:WaitForChild("Weld")
if Weld then
if PartToDelete.Name == "LandPart" then
Weld:Destroy()
end
end
end
for count = 1, #Model:GetChildren() do
DeleteRandomPart()
wait(.1)
if not #Model:GetChildren() then
Model:Destroy()
break
end
end
Your script iterates all children of the model. If not all parts of the model have welds or are named “LandPart” then the script will just skip over them with a 0.1 second wait. Try removing the wait(.1) and see if it breaks all welds
Nothing’s happening. I only want the script to break the welds of certain parts.
local Model = workspace.Grassland
local function DeleteRandomPart()
local ChildrenOfModel = Model:GetChildren()
local PartToDelete = ChildrenOfModel[math.random(#ChildrenOfModel)]
local Weld = PartToDelete:FindFirstChildOfClass("Weld")
if Weld and PartToDelete.Name == "LandPart" then
Weld:Destroy()
end
end
for count = 1, #Model:GetChildren() do --repeats the line below for the number of children in the model
DeleteRandomPart()
wait(1)
if not #Model:GetChildren() then
Model:Destroy()
break
end
end
local Model = workspace.Grassland
local Parts = {}
-- store all parts named LandPart in array
for i, Part in pairs(Model:GetChildren()) do
if Part.Name == "LandPart" then
table.insert(Parts, Part)
end
end
-- delete part from the array of stored parts
local function DeleteRandomPart()
local PartToDelete = table.remove(Parts, math.random(#Parts))
local Weld = PartToDelete:FindFirstChildOfClass("Weld")
if Weld then
Weld:Destroy()
end
end
for i = 1, #Parts do
DeleteRandomPart()
if #Parts <= 0 then
Model:Destroy()
break
end
wait()
end
local Model = workspace.Grassland
local Parts = {}
-- store all parts named LandPart in array
for i, Part in pairs(Model:GetChildren()) do
if Part.Name == "LandPart" then
table.insert(Parts, Part)
end
end
print("Number of parts:", #Parts)
-- delete part from the array of stored parts
local function DeleteRandomPart()
local PartToDelete = table.remove(Parts, math.random(#Parts))
local Weld = PartToDelete:FindFirstChildOfClass("Weld")
if Weld then
Weld:Destroy()
print'Destroyed Weld'
end
end
for i = 1, #Parts do
DeleteRandomPart()
if #Parts <= 0 then
Model:Destroy()
print'Destroyed Model'
break
end
wait(0.2)
end