I’ve created this script that produces welds in a structure. It then deletes those welds to give the effect that the structure is collapsing.
However, after the welds are deleted, it gives me this error to which I have tried countering so many times. I’m not sure what to do here. I’ve even tried wrapping the error into a conditional statement, but to no avail. The welds are placed within a single Part called Base.
local structureDebris = workspace.StructureTest:GetChildren()
local structurePrimary = workspace.StructureTest.PrimaryPart
for k = 1,#structureDebris do
if structureDebris[k]:IsA("Part") or structureDebris[k]:IsA("WedgePart")then
local weld = Instance.new("Weld")
weld.Part0 = structurePrimary
weld.Part1 = structureDebris[k]
weld.C0 = structurePrimary.CFrame:Inverse()
weld.C1 = structureDebris[k].CFrame:inverse()
weld.Parent = structurePrimary
end
end
while true do
wait(.5)
if workspace.StructureTest.Base:GetChildren() ~= nil then
workspace.StructureTest.Base.Weld:Destroy() --Problem here
elseif workspace.StructureTest.Base:GetChildren() == nil then
break
end
end
Basically in that line you’re assuming that the weld exists, to avoid that you could simply check before doing anything to it. you can use the following:
if workspace.StructureTest.Base:FindFirstChildOfClass("Weld") then
workspace.StructureTest.Base:FindFirstChildOfClass("Weld"):Destroy()
end
AFAIC, sometimes using “workspace” in LocalScripts (although this is a ServerScript case) RARELY used to return nil, but i think things have changed. anyway, thank you
Buggy in what sense exactly? If you’re talking about the service not being available when referencing the workspace global, I wouldn’t consider that a bug. Its more of an issue with limitations on how fast things can replicate in.
When I have tried to use workspace directly it would just return and not run the rest of my code. It makes no sense, but when I changed it to game:GetService(“Workspace”) it worked completely fine.