Advertisement
Nosssa

UNIVERSAL Stefanuk Aim Viewer

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