There are only 2 possible parents, 'Model' and 'Earthquake Area' My error: Workspace.Earthquake:19: attempt to index field ‘?’ (a nil value) This is the small piece that is giving me the error:
if Parts[x].Parent == nil
I looked for solutions, but none helped me.
Parts = {}
local shakeVal = script.shakeVal
shkMagnitude = 200-script.ShakeMagnitude.Value -- change up here if value increase; change the literal value too
function GetParts(h)
local g = h:GetChildren()
for z = 1, #g do
if g[z]:IsA("Folder") or g[z]:IsA("Configuration") or g[z]:IsA("Model") then
GetParts(g[z])
elseif g[z]:IsA("MeshPart") or g[z]:IsA("UnionOperation") or g[z]:IsA("SpawnLocation") or g[z]:IsA("WedgePart") or g[z]:IsA("CornerWedgePart") or g[z]:IsA("Part") then
table.insert(Parts,z,g[z])
end
end
end
GetParts(workspace.EarthquakeArea)
print("nice")
wait(1)
repeat
for x = 1, #Parts do
if Parts[x].Parent == nil then
warn("Parts: "..Parts[x]:GetFullName().." Is already destroyed by something!")
else
print(Parts[x].Parent.Name)
print(Parts[x]:GetFullName())
local copy = game.ReplicatedStorage.TouchDamage:Clone()
copy.Parent = Parts[x]
Parts[x].Anchored = false
Parts[x]:BreakJoints()
Parts[x].RotVelocity = Vector3.new(0,shakeVal.Value,0) -- change shakeVal for rotation speed (default 5)
wait()
Parts[x].RotVelocity = Vector3.new(0,0,0)

2 comments
There are 2 things which do not sit well with me. First: The line given in your error output is different from the code you provided. Second: I do not see where "Parts" is defined.
Parts is defined at the top. Also, I put 2 scripts into this post on accident. This is the script I'm having trouble with.