Awenoxd

highlight for roblox

Dec 8th, 2024 (edited)
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.72 KB | None | 0 0
  1. -- This script can be run in the Roblox Studio's command bar (console)
  2.  
  3. local Players = game:GetService("Players")
  4. local Workspace = game:GetService("Workspace")
  5. local RunService = game:GetService("RunService")
  6. local localPlayer = Players.LocalPlayer
  7.  
  8. -- Table to hold active tracers for all players
  9. local activeTracers = {}
  10.  
  11. -- Function to create or update the tracer for a player
  12. local function createOrUpdateTracer(player)
  13.     local character = player.Character
  14.     if character then
  15.         local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
  16.         if humanoidRootPart then
  17.             -- Check if tracer already exists for this player
  18.             if not activeTracers[player] then
  19.                 -- Create a new tracer part
  20.                 local tracer = Instance.new("Part")
  21.                 tracer.Size = Vector3.new(0.1, 0.1, 1) -- Set initial size (thin and long)
  22.                 tracer.Anchored = true
  23.                 tracer.CanCollide = false
  24.                 tracer.Material = Enum.Material.Neon
  25.                 tracer.BrickColor = BrickColor.new("Blue") -- Tracer color
  26.                 tracer.Transparency = 0.5 -- Semi-transparent
  27.                 tracer.Parent = Workspace
  28.  
  29.                 -- Store the tracer in the activeTracers table
  30.                 activeTracers[player] = tracer
  31.             end
  32.  
  33.             -- Update the tracer's position and orientation based on your position and the player's position
  34.             local tracer = activeTracers[player]
  35.             local playerPosition = humanoidRootPart.Position
  36.             local myPosition = localPlayer.Character:FindFirstChild("HumanoidRootPart").Position
  37.             local direction = (playerPosition - myPosition).unit
  38.             local distance = (playerPosition - myPosition).Magnitude
  39.  
  40.             -- Update the tracer's size and position based on distance
  41.             tracer.Size = Vector3.new(0.1, 0.1, distance) -- Stretch the tracer to the player's position
  42.             tracer.CFrame = CFrame.new(myPosition, playerPosition) * CFrame.new(0, 0, -distance / 2) -- Position tracer at midpoint between your position and the player
  43.         end
  44.     end
  45. end
  46.  
  47. -- Function to create or update highlights for all players
  48. local function createOrUpdateHighlights()
  49.     for _, player in ipairs(Players:GetPlayers()) do
  50.         if player ~= localPlayer then
  51.             local character = player.Character
  52.             if character then
  53.                 -- Check if a highlight already exists for this player
  54.                 local existingHighlight = character:FindFirstChildOfClass("Highlight")
  55.                 if not existingHighlight then
  56.                     local highlight = Instance.new("Highlight")
  57.                     highlight.Adornee = character -- Set the adornee to the player's character
  58.                     highlight.FillColor = Color3.fromRGB(0, 255, 0) -- Green color
  59.                     highlight.FillTransparency = 0.5 -- Semi-transparent fill
  60.                     highlight.OutlineColor = Color3.fromRGB(255, 255, 0) -- Yellow outline
  61.                     highlight.OutlineTransparency = 0.3 -- Semi-transparent outline
  62.                     highlight.Parent = character
  63.                 end
  64.             end
  65.         end
  66.     end
  67. end
  68.  
  69. -- Continuously update the tracers and highlights
  70. RunService.Heartbeat:Connect(function()
  71.     createOrUpdateHighlights()
  72.     for _, player in ipairs(Players:GetPlayers()) do
  73.         if player ~= localPlayer then
  74.             createOrUpdateTracer(player)
  75.         end
  76.     end
  77. end)
  78.  
  79. -- Cleanup tracers when players leave
  80. Players.PlayerRemoving:Connect(function(player)
  81.     if activeTracers[player] then
  82.         activeTracers[player]:Destroy()
  83.         activeTracers[player] = nil
  84.     end
  85. end)
  86.  
Advertisement
Add Comment
Please, Sign In to add comment