Advertisement
VenoxComeback

aimviewasdwa

Apr 16th, 2025
8
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.03 KB | None | 0 0
  1. -- Services
  2. local Players = game:GetService("Players")
  3. local RunService = game:GetService("RunService")
  4. local Workspace = game:GetService("Workspace")
  5.  
  6. -- Local player reference
  7. local LocalPlayer = Players.LocalPlayer
  8.  
  9. -- Table to store beams
  10. local Beams = {}
  11.  
  12. -- Function to create a beam for a player
  13. local function createBeam(player)
  14. if player == LocalPlayer then return end
  15.  
  16. local function onCharacterAdded(character)
  17. local head = character:WaitForChild("Head", 5)
  18. local bodyEffects = character:WaitForChild("BodyEffects", 5)
  19. local mousePos = bodyEffects and bodyEffects:FindFirstChild("MousePos")
  20.  
  21. if head and mousePos then
  22. -- Create attachments
  23. local att0 = Instance.new("Attachment", head)
  24. local att1 = Instance.new("Attachment", Workspace.Terrain)
  25.  
  26. -- Create beam
  27. local beam = Instance.new("Beam")
  28. beam.Attachment0 = att0
  29. beam.Attachment1 = att1
  30. beam.FaceCamera = true
  31. beam.Width0 = 0.2
  32. beam.Width1 = 0.2
  33. beam.Color = ColorSequence.new(Color3.fromRGB(255, 58, 61))
  34. beam.Transparency = NumberSequence.new(1) -- Initially invisible
  35. beam.Parent = att0
  36.  
  37. -- Store in Beams table
  38. Beams[player] = {Beam = beam, Att1 = att1, MousePos = mousePos, Character = character}
  39. end
  40. end
  41.  
  42. -- Connect to CharacterAdded event
  43. player.CharacterAdded:Connect(onCharacterAdded)
  44.  
  45. -- If character already exists, create beam
  46. if player.Character then
  47. onCharacterAdded(player.Character)
  48. end
  49. end
  50.  
  51. -- Create beams for existing players
  52. for _, player in ipairs(Players:GetPlayers()) do
  53. createBeam(player)
  54. end
  55.  
  56. -- Create beams for new players
  57. Players.PlayerAdded:Connect(function(player)
  58. createBeam(player)
  59. end)
  60.  
  61. -- Update beams every frame
  62. RunService.RenderStepped:Connect(function()
  63. for player, data in pairs(Beams) do
  64. local character = data.Character
  65. if character and character.Parent then
  66. local hasTool = false
  67. for _, tool in ipairs(player.Backpack:GetChildren()) do
  68. if tool:IsA("Tool") then
  69. hasTool = true
  70. break
  71. end
  72. end
  73. for _, tool in ipairs(character:GetChildren()) do
  74. if tool:IsA("Tool") then
  75. hasTool = true
  76. break
  77. end
  78. end
  79.  
  80. if hasTool and data.MousePos then
  81. data.Att1.Position = data.MousePos.Value
  82. data.Beam.Transparency = NumberSequence.new(0) -- Visible
  83. else
  84. data.Beam.Transparency = NumberSequence.new(1) -- Invisible
  85. end
  86. else
  87. -- Cleanup if character is not valid
  88. if data.Beam then data.Beam:Destroy() end
  89. if data.Att1 then data.Att1:Destroy() end
  90. Beams[player] = nil
  91. end
  92. end
  93. end)
  94.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement