When you say :
for i, object in pairs(game.Workspace.topLawn:GetChildren()) do
lawnPiece = object
end
You are just switching local lawnPiece into one of topLawn's objects then quickly assigning it to another one.
You are just doing this:
lawnPiece = game.Workspace.topLawn.Part
lawnPiece = game.Workspace.topLawn.Part
lawnPiece = game.Workspace.topLawn.Part
lawnPiece = game.Workspace.topLawn.Wedge
lawnPiece = game.Workspace.topLawn.Part
lawnPiece = game.Workspace.topLawn.Part
You cannot assign all of those into one variable without making a table. But in your case, it is better to just run the loop to destroy all of topLawn's descendants in the function itself.
Full complete code:
function onMow(hit)
if hit.Parent.Name == game.ServerStorage.lawnMower.Name then
for i, object in pairs(game.Workspace.topLawn:GetChildren()) do
object:Destroy()
end
end
end
lawnPiece.Touched:connect(onMow)
You might want to consider doing this instead.
function onMow(hit)
if hit.Parent.Name == game.ServerStorage.lawnMower.Name then
workspace.topLawn:Destroy()
end
end
lawnPiece.Touched:connect(onMow)
But I am not entirely sure you want to do next so you might not want to use the extra code above. The code above just destroys the whole topLawn in one tick.