How would I create a part where the beam touches another part? [closed]
Here's the code, I want to make the "Explosion" part wherever the beam part touches the part it hits. Here's the code:
01 | local tool = script.Parent |
02 | local player = game:GetService( "Players" ).LocalPlayer |
04 | tool.Equipped:connect( function (mouse) |
05 | print ( "Tool equipped!" ) |
07 | mouse.Button 1 Down:connect( function () |
08 | print ( "Mouse pressed!" ) |
09 | local ray = Ray.new(tool.Handle.CFrame.p, (mouse.Hit.p - tool.Handle.CFrame.p).unit * 300 ) |
10 | local part, position = workspace:FindPartOnRay(ray, player.Character, false , true ) |
12 | local beam = Instance.new( "Part" , workspace) |
13 | beam.BrickColor = BrickColor.Yellow() |
14 | beam.FormFactor = "Custom" |
15 | beam.Material = "Neon" |
16 | beam.Transparency = 0.25 |
19 | beam.CanCollide = false |
23 | local distance = (tool.Handle.CFrame.p - position).magnitude |
24 | beam.Size = Vector 3. new(. 5 , . 5 , distance) |
25 | beam.CFrame = CFrame.new(tool.Handle.CFrame.p, position) * CFrame.new( 0 , 0 , -distance / 2 ) |
26 | local explosion = Instance.new( "Part" , workspace) |
27 | explosion.Shape = "Ball" |
28 | explosion.BrickColor = BrickColor.Yellow() |
29 | explosion.Transparency = 0.25 |
30 | explosion.Size = Vector 3. new( 25 , 25 , 25 ) |
31 | explosion.Position = Vector 3. new(. 5 , . 5 , distance) |
32 | explosion.Anchored = true |
33 | explosion.CanCollide = false |
34 | explosion.Material = "Neon" |
35 | local ex = Instance.new( "Explosion" ) |
37 | ex.Position = Vector 3. new( 10 , 10 , 10 ) |
40 | game:GetService( "Debris" ):AddItem(beam, . 7 ) |
43 | local humanoid = part.Parent:FindFirstChild( "Humanoid" ) |
46 | humanoid = part.Parent.Parent:FindFirstChild( "Humanoid" ) |
50 | humanoid:TakeDamage( 30 ) |
52 | script.Parent.Reload.Disabled = false |
53 | script.Disabled = true |