Can someone tell me what the problem is with my .Touched Event Part? I've tested this script multiple times and the Part Exp which is the large custom explosion radius in game?
Mouse.Button1Down:connect(function() if not (ShootDeb) and (Ammo ~= 0) then ShootDeb = true Ammo = Ammo - 1 Missle = Instance.new("Part",Mod) Missle.Name = "Missle" Missle.Size = Vector3.new(1.6, 1.8, 4.2) Missle.BrickColor = BrickColor.new("Really black") MMesh = Instance.new("SpecialMesh",Missle) MMesh.Name = "MMesh" MMesh.MeshType = "FileMesh" MMesh.MeshId = "http://roblox.com/asset/?id=2251534" MMesh.Scale = Vector3.new(0.5, 0.6, 0.3) Missle.CFrame = Hole.CFrame*CFrame.new(0,-7,0) BodyV = Instance.new("BodyVelocity",Missle) BodyV.maxForce = Vector3.new(math.huge,math.huge,math.huge) wait(0.01) Missle.CFrame = CFrame.new(Missle.Position,Mouse.Hit.p) BodyV.velocity = Missle.CFrame.lookVector*130 Missle.Touched:connect(function(Hit) BodyV:Destroy() Exp = Instance.new("Part",workspace) Exp.CanCollide = false Exp.Anchored = true Exp.CFrame = Missle.CFrame Exp.Name = "Exp" Exp.Locked = true Exp.TopSurface = "Smooth" Exp.BottomSurface = "Smooth" Exp.Shape = "Ball" Exp.BrickColor = BrickColor.new("Bright yellow") Exp.Transparency = 0.5 Exp2 = Exp:Clone() Exp2.CFrame = Exp.CFrame Exp2.Parent = workspace Exp2.Name = "Exp2" Exp2.BrickColor = BrickColor.new("Neon orange") Exp3 = Exp:Clone() Exp3.CFrame = Exp2.CFrame Exp3.Parent = workspace Exp3.Name = "Exp2" Exp3.BrickColor = BrickColor.new("Bright red") Missle:Destroy() for i = 1, 24 do wait(0.01) Exp.Size = Vector3.new(i,i,i) Exp2.Size = Vector3.new(i - 4 , i- 4 , i - 4) Exp3.Size = Vector3.new(i - 6 , i- 6 , i - 6) end wait(0.01) Exp:Destroy() Exp2:Destroy() Exp3:Destroy() Exp.Touched:connect(function(Hit) local FindH = Hit.Parent:findFirstChild("Humanoid") if (FindH ~= nil) then FindH.Humanoid:TakeDamage(math.random(40,78)) end end) game.Debris:AddItem(Missle,8) wait(4) ShootDeb = false end) end end)
Your problem is coming from trying to connect an event to a nil value. You use the :Destroy()
method on "Exp", which completely removes it from the game and disconnects any connections attached to it. Right after it was destroyed, you attempted to connect the Touched
event to it, which will error because "Exp" doesn't exist. I would suggest moving it to a place before the for loop.
Hope this helped!