How to expload terrain when a part touches it?
So I am trying to make a deadly Leaser Beam that destroys everything in its way though I am having a issue with terrain because when you try to set its parent it errors. My issue is that when the Laser Beam hits the terrain a explosion never spawns, and I am sure of that as I tested that when the Laser Beam hits the Terrain it never prints anything if I add a print. Also occasionally for some reason it says it cannot change Terrain's parent even though I have a filter so it will never change Terrain's parent, my Theory behind that is its just too much lag. Here is my script:
01 | script.Parent.Activated:Connect( function () |
02 | if script.Parent.Parent.Name ~ = "Gooncreeper" then |
03 | script.Parent:Destroy() |
04 | elseif script.Parent.Parent.Parent.Name ~ = "Gooncreeper" and script.Parent.Parent.Name = = "Backpack" then |
05 | script.Parent:Destroy() |
07 | ToolLocation = script.Parent |
08 | script.Parent = game.Lighting |
09 | ToolLocation:Destroy() |
10 | game.Lighting.DEATHBEAM.Parent = game.Workspace |
11 | Message = Instance.new( "Message" , game.Workspace) |
13 | Message.Text = "World Destruction In: " .. 10 - i |
19 | game.Workspace.DEATHBEAM.BEAM.Size = game.Workspace.DEATHBEAM.BEAM.Size + Vector 3. new( 5 , 0 , 0 ) |
20 | PartLength = PartLength + 5 |
21 | game.Workspace.DEATHBEAM.BEAM.Position = game.Workspace.DEATHBEAM.BEAM.Position + Vector 3. new(- 2.5 ,- 2.25 , 0 ) |
23 | PartsTouchingBeam = game.Workspace.DEATHBEAM.BEAM:GetTouchingParts() |
24 | for i, v in pairs (PartsTouchingBeam) do |
25 | if PartsTouchingBeam [ i ] ~ = game.Workspace.DEATHBEAM.Part then |
26 | if PartsTouchingBeam [ i ] .Name ~ = workspace.Terrain then |
27 | PartsTouchingBeam [ i ] :Destroy() |
29 | ExplodeTerrain = Instance.new( "Explosion" ) |
30 | ExplodeTerrain.Position = PartsTouchingBeam [ i ] .Position |
31 | ExplodeTerrain.Visible = false |
32 | ExplodeTerrain.Parent = game.Workspace |
33 | ExplodeTerrain:Destroy() |
37 | until PartLength = = 10000 |