Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Can you make it when if you shoot, it explodes at where you fire? thanks [closed]

Asked by 3 years ago

Heres what i want to be it:

http://cdn.discordapp.com/attachments/735406102992388107/768533390625734676/unknown.png

Code:

01  tool = script.Parent
02  player = game:GetService("Players").LocalPlayer
03   
04  tool.Equipped:Connect(function(mouse)
05      print("Tool equipped!")
06   
07      mouse.Button1Down:Connect(function()
08          print("Mouse clicked!")
09          tool.GunSound:Play()
10   
11          if player.Character.Humanoid.Health > 0 then
12              local ray = Ray.new(tool.Dispenser.CFrame.p, (mouse.Hit.p - tool.Dispenser.CFrame.p).unit * 600)
13              local part, position = game.Workspace:FindPartOnRay(ray, player.Character, false, true)
14   
15              local beam = Instance.new("Part", game.Workspace)
16              beam.BrickColor = player.TeamColor
17              beam.Material = Enum.Material.Neon
18              beam.Transparency = .3
19              beam.Anchored = true
20              beam.Locked = true
21              beam.CanCollide = false
22   
23              local distance = (tool.Dispenser.CFrame.p - position).magnitude
24              beam.Size = Vector3.new(.3, .3, distance)
25              beam.CFrame = CFrame.new(tool.Dispenser.CFrame.p, position) * CFrame.new(0, 0, -distance / 2)
26   
27              game:GetService("Debris"):AddItem(beam, 0.05)
28   
29              if part then
30                  local humanoid = part.Parent:FindFirstChild("Humanoid")
31                  if not humanoid then
32                      humanoid = part.Parent.Parent:FindFirstChild("Humanoid")
33                  end
34   
35                  if humanoid then
36                      local Explosion = Instance.new("Explosion")
37                      Explosion.Position = ray.Handle.Position
38                      Explosion.Parent = ray
39                      humanoid.Health = humanoid.Health - 30
40                      if humanoid.Health > 0 then
41                          player.leaderstats.Points.Value = player.leaderstats.Points.Value + 1
42                      end
43                  end
44              end
45              wait(0)
46          end
47      end)
48  end)
0
You can't just come here to ask someone to MAKE a script for you without any attempt User#32819 0 — 3y

Closed as Not Constructive by User#32819 and raid6n

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?