Can you make it when if you shoot, it explodes at where you fire? thanks [closed]
Heres what i want to be it:
http://cdn.discordapp.com/attachments/735406102992388107/768533390625734676/unknown.png
Code:
01 | 01 tool = script.Parent |
02 | 02 player = game:GetService( "Players" ).LocalPlayer |
04 | 04 tool.Equipped:Connect( function (mouse) |
05 | 05 print ( "Tool equipped!" ) |
07 | 07 mouse.Button 1 Down:Connect( function () |
08 | 08 print ( "Mouse clicked!" ) |
09 | 09 tool.GunSound:Play() |
11 | 11 if player.Character.Humanoid.Health > 0 then |
12 | 12 local ray = Ray.new(tool.Dispenser.CFrame.p, (mouse.Hit.p - tool.Dispenser.CFrame.p).unit * 600 ) |
13 | 13 local part, position = game.Workspace:FindPartOnRay(ray, player.Character, false , true ) |
15 | 15 local beam = Instance.new( "Part" , game.Workspace) |
16 | 16 beam.BrickColor = player.TeamColor |
17 | 17 beam.Material = Enum.Material.Neon |
18 | 18 beam.Transparency = . 3 |
19 | 19 beam.Anchored = true |
21 | 21 beam.CanCollide = false |
23 | 23 local distance = (tool.Dispenser.CFrame.p - position).magnitude |
24 | 24 beam.Size = Vector 3. new(. 3 , . 3 , distance) |
25 | 25 beam.CFrame = CFrame.new(tool.Dispenser.CFrame.p, position) * CFrame.new( 0 , 0 , -distance / 2 ) |
27 | 27 game:GetService( "Debris" ):AddItem(beam, 0.05 ) |
30 | 30 local humanoid = part.Parent:FindFirstChild( "Humanoid" ) |
31 | 31 if not humanoid then |
32 | 32 humanoid = part.Parent.Parent:FindFirstChild( "Humanoid" ) |
36 | 36 local Explosion = Instance.new( "Explosion" ) |
37 | 37 Explosion.Position = ray.Handle.Position |
38 | 38 Explosion.Parent = ray |
39 | 39 humanoid.Health = humanoid.Health - 30 |
40 | 40 if humanoid.Health > 0 then |
41 | 41 player.leaderstats.Points.Value = player.leaderstats.Points.Value + 1 |