IHackShootingGames

Laser

Sep 11th, 2014
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. local tool = script.Parent
  2. local user
  3.  
  4. --when the tool is equipped
  5. tool.Equipped:connect(function(mouse)
  6. --store the character of the person using the tool
  7. user = tool.Parent
  8.  
  9. --when the left mouse button is clicked
  10. mouse.Button1Down:connect(function()
  11. --make and do a hit test along the ray
  12. local ray = Ray.new(tool.Handle.CFrame.p, (mouse.Hit.p - tool.Handle.CFrame.p).unit*300)
  13. local hit, position = game.Workspace:FindPartOnRay(ray, user)
  14.  
  15. --do damage to any humanoids hit
  16. local humanoid = hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid")
  17. if humanoid then
  18. humanoid:TakeDamage(30)
  19. end
  20.  
  21. --draw the ray
  22. local distance = (position - tool.Handle.CFrame.p).magnitude
  23. local rayPart = Instance.new("Part", user)
  24. rayPart.Name = "RayPart"
  25. rayPart.BrickColor = BrickColor.new("Bright red")
  26. rayPart.Transparency = 0.5
  27. rayPart.Anchored = true
  28. rayPart.CanCollide = false
  29. rayPart.TopSurface = Enum.SurfaceType.Smooth
  30. rayPart.BottomSurface = Enum.SurfaceType.Smooth
  31. rayPart.formFactor = Enum.FormFactor.Custom
  32. rayPart.Size = Vector3.new(0.2, 0.2, distance)
  33. rayPart.CFrame = CFrame.new(position, tool.Handle.CFrame.p) * CFrame.new(0, 0, -distance/2)
  34.  
  35. --add it to debris so it disappears after 0.1 seconds
  36. game.Debris:AddItem(rayPart, 0.1)
  37. end)
  38. end)
Advertisement
Add Comment
Please, Sign In to add comment