SpamDuk3

Da Hood: Show Where People Are Aiming, Very Overpowered

Dec 10th, 2022
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.76 KB | Gaming | 0 0
  1. --[[
  2. Information:
  3.  
  4. - This shows you where people are aiming.
  5. - By default: red = aiming at you = danger, green = aiming away from you = safe
  6. ]]
  7.  
  8. -- // Services
  9. local Players = game:GetService("Players")
  10. local Workspace = game:GetService("Workspace")
  11.  
  12. -- // Vars
  13. local Terrain = Workspace.Terrain
  14. local LocalPlayer = Players.LocalPlayer
  15. local Beams = {}
  16.  
  17. local Colours = {
  18. At = ColorSequence.new(Color3.new(1, 0, 0), Color3.new(1, 0, 0)),
  19. Away = ColorSequence.new(Color3.new(0, 1, 0), Color3.new(0, 1, 0))
  20. }
  21.  
  22. -- // Checks if the beam is hitting our character and can't go through walls
  23. local function IsBeamHit(Beam: Beam, MousePos: Vector3)
  24. -- // Get our character
  25. local Character = LocalPlayer.Character
  26. local Attachment = Beam.Attachment1
  27.  
  28. -- // Workout the direction
  29. local Origin = Beam.Attachment0.WorldPosition
  30. local Direction = MousePos - Origin
  31.  
  32. -- // Fire the ray, making sure it hits something (should unless aiming at sky?)
  33. local raycastParms = RaycastParams.new()
  34. raycastParms.FilterDescendantsInstances = {Character, Workspace.CurrentCamera}
  35. local RaycastResult = Workspace:Raycast(Origin, Direction * 2, raycastParms) -- // Multiplied by 2 as ray might fall too short
  36. if (not RaycastResult) then
  37. Beam.Color = Colours.Away
  38. Attachment.WorldPosition = MousePos
  39. return
  40. end
  41.  
  42. -- // Set the colour based upon if aiming at us or not
  43. if (Character) then
  44. Beam.Color = RaycastResult.Instance:IsDescendantOf(Character) and Colours.At or Colours.Away
  45. end
  46.  
  47. -- // Set the position so the beam can't go through walls
  48. Attachment.WorldPosition = RaycastResult.Position
  49. end
  50.  
  51. -- // Creates a beam with the default properties
  52. local function CreateBeam(Character: Model)
  53. -- // Create beam
  54. local Beam = Instance.new("Beam", Character)
  55.  
  56. -- // Set important properties
  57. Beam.Attachment0 = Character:WaitForChild("Head"):WaitForChild("FaceCenterAttachment")
  58. Beam.Enabled = Character:FindFirstChild("GunScript", true) ~= nil
  59.  
  60. -- // Set visual properties
  61. Beam.Width0 = 0.1
  62. Beam.Width1 = 0.1
  63.  
  64. -- // Add to beam table so can modify all at once
  65. table.insert(Beams, Beam)
  66.  
  67. -- // Return
  68. return Beam
  69. end
  70.  
  71. -- // Apply whenever we get a new character
  72. local function OnCharacter(Character: Model | nil)
  73. -- // Make sure character exists
  74. if (not Character) then
  75. return
  76. end
  77.  
  78. -- // Wait for the MousePos
  79. local MousePos = Character:WaitForChild("BodyEffects"):WaitForChild("MousePos")
  80.  
  81. -- // Create the beam
  82. local Beam = CreateBeam(Character)
  83.  
  84. -- // Attachment for the mouse position
  85. local Attachment = Instance.new("Attachment", Terrain)
  86. Beam.Attachment1 = Attachment
  87.  
  88. -- // Constantly update when MousePos updates
  89. IsBeamHit(Beam, MousePos.Value)
  90. MousePos.Changed:Connect(function()
  91. IsBeamHit(Beam, MousePos.Value)
  92. end)
  93.  
  94. -- // See whenever they equip a gun
  95. Character.DescendantAdded:Connect(function(Descendant)
  96. -- // Check if it is a gun, set enabled
  97. if (Descendant.Name == "GunScript") then
  98. Beam.Enabled = true
  99. end
  100. end)
  101.  
  102. -- // See whenever they unequip a gun
  103. Character.DescendantRemoving:Connect(function(Descendant)
  104. -- // Check if it is a gun, set disabled
  105. if (Descendant.Name == "GunScript") then
  106. Beam.Enabled = false
  107. end
  108. end)
  109. end
  110.  
  111. -- // Apply on each player
  112. local function OnPlayer(Player: Player)
  113. OnCharacter(Player.Character)
  114. Player.CharacterAdded:Connect(OnCharacter)
  115. end
  116.  
  117. for _, v in ipairs(Players:GetPlayers()) do
  118. OnPlayer(v)
  119. end
  120.  
  121. -- // Redo for each new player
  122. Players.PlayerAdded:Connect(OnPlayer)
Tags: Roblox Script
Add Comment
Please, Sign In to add comment