Basically, I'm building a nuke where when it detonates it destroys any parts in it's radius, but if it's a player they lose HP. However, it's not working and instead leaves the parts it's supposed to destroy and destroys any parts that it comes in contact afterwards. The error says that I'm attempting to index field parent, because it's a nil value. Any help?
local explosion = Instance.new("Part",workspace)
explosion.Position = script.Parent.thing.Position
wait(0.1)
explosion.Shape = "Ball"
explosion.BrickColor = BrickColor.new("Bright green")
explosion.Material = "Foil"
explosion.CanCollide = false
explosion.Anchored = true
explosion.Transparency = 0.25
for i = 5,0,-1 do
explosion.Size = explosion.Size * 2
wait(0.3)
explosion.Touched:Connect(function(touch)
if touch.Parent:FindFirstChild("Humanoid") then
touch.Parent.Humanoid:TakeDamage(100)
else
touch:Destroy()
end
end)
end
script.Parent.Nuke:Destroy()

4 comments
Please post the full output error.
After you :Destroy() the part, it's parent will become nil, so you can no longer refer to the parent of 'touch' in the script after line 19 occurs.
@incapaz attempt to index field 'Parent' ( a nil value )
Matt, how can I fix it then?