Advertisement
Hades126

Roblox ESP

Nov 15th, 2024
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.65 KB | None | 0 0
  1. local Players = game:GetService("Players")
  2. local LocalPlayer = Players.LocalPlayer
  3. local MaxRange = 325 -- Set the maximum range for highlights
  4. local RunService = game:GetService("RunService") -- To track heartbeat updates
  5.  
  6. -- Function to apply the highlight to a player (visible only to local player)
  7. local function ApplyHighlight(Player)
  8. -- Skip highlighting the local player
  9. if Player == LocalPlayer then return end
  10.  
  11. -- Wait for the player's character to load
  12. local Character = Player.Character or Player.CharacterAdded:Wait()
  13. local Humanoid = Character:WaitForChild("Humanoid")
  14.  
  15. -- Create a Highlight instance
  16. local HightLighter = Instance.new("Highlight")
  17. HightLighter.Parent = Character -- Parent to the character so it's attached
  18.  
  19. -- Set the highlight's properties
  20. HightLighter.FillTransparency = 1 -- Make the body fill fully transparent
  21. HightLighter.OutlineTransparency = 0 -- Make the outline fully visible
  22. HightLighter.OutlineColor = Color3.fromRGB(255, 0, 0) -- Red outline
  23.  
  24. -- Create a BillboardGui to show the health bar
  25. local BillboardGui = Instance.new("BillboardGui")
  26. BillboardGui.Parent = Character
  27. BillboardGui.Adornee = Character.Head -- Attach the BillboardGui to the player's head
  28. BillboardGui.Size = UDim2.new(0, 50, 0, 5) -- Set the size of the health bar
  29. BillboardGui.StudsOffset = Vector3.new(0, 3, 0) -- Position the health bar above the head
  30.  
  31. -- Create a Frame to represent the health bar
  32. local HealthBar = Instance.new("Frame")
  33. HealthBar.Parent = BillboardGui
  34. HealthBar.Size = UDim2.new(1, 0, 1, 0) -- Full width of the BillboardGui
  35. HealthBar.BackgroundTransparency = 1 -- Make background transparent
  36.  
  37. -- Create a health bar foreground (the actual health bar)
  38. local HealthBarForeground = Instance.new("Frame")
  39. HealthBarForeground.Parent = HealthBar
  40. HealthBarForeground.Size = UDim2.new(1, 0, 1, 0) -- Full size of the parent frame
  41. HealthBarForeground.BackgroundTransparency = 0 -- Make the health bar visible
  42. HealthBarForeground.BorderSizePixel = 0 -- Remove border
  43.  
  44. -- Function to update the health bar based on the player's health
  45. local function UpdateHealthBar()
  46. local healthRatio = Humanoid.Health / Humanoid.MaxHealth
  47.  
  48. -- Set health bar width based on health ratio
  49. HealthBarForeground.Size = UDim2.new(healthRatio, 0, 1, 0)
  50.  
  51. -- Color the health bar based on health ratio
  52. if healthRatio > 0.66 then
  53. -- Green
  54. HealthBarForeground.BackgroundColor3 = Color3.fromRGB(0, 255, 0)
  55. elseif healthRatio > 0.33 then
  56. -- Orange
  57. HealthBarForeground.BackgroundColor3 = Color3.fromRGB(255, 165, 0)
  58. else
  59. -- Red
  60. HealthBarForeground.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
  61. end
  62. end
  63.  
  64. -- Update the health bar whenever the player's health changes
  65. Humanoid.HealthChanged:Connect(UpdateHealthBar)
  66.  
  67. -- Initial health bar update
  68. UpdateHealthBar()
  69.  
  70. -- Optional: Health monitor to remove the highlight when the player dies
  71. local function Disconnect()
  72. HightLighter:Remove()
  73. BillboardGui:Remove() -- Remove the health bar when the player dies
  74. end
  75.  
  76. Humanoid:GetPropertyChangedSignal("Health"):Connect(function()
  77. if Humanoid.Health <= 0 then
  78. Disconnect()
  79. end
  80. end)
  81. end
  82.  
  83. -- Function to apply the highlight only for enemies (based on teams)
  84. local function ApplyEnemyHighlight()
  85. -- Loop through all players in the game
  86. for _, Player in next, Players:GetPlayers() do
  87. -- If the player is not the local player, check their team and distance
  88. if Player ~= LocalPlayer then
  89. -- Check if player is within the MaxRange distance
  90. local Character = Player.Character
  91. if Character and Character:FindFirstChild("HumanoidRootPart") then
  92. local Distance = (LocalPlayer.Character.HumanoidRootPart.Position - Character.HumanoidRootPart.Position).Magnitude
  93.  
  94. if Distance <= MaxRange then -- Check if the target is within range
  95. -- If the local player is on a team and the enemy is on a different team
  96. if LocalPlayer.Team and Player.Team and LocalPlayer.Team ~= Player.Team then
  97. -- Apply the highlight if they're an enemy
  98. ApplyHighlight(Player)
  99. elseif not LocalPlayer.Team then
  100. -- If the local player is not on a team, highlight everyone except the local player
  101. ApplyHighlight(Player)
  102. end
  103. end
  104. end
  105. end
  106. end
  107. end
  108.  
  109. -- Function to ensure new players are highlighted upon joining
  110. local function OnPlayerAdded(Player)
  111. -- When a new player joins, wait briefly to ensure their character is loaded, then apply the highlight
  112. wait(1) -- Wait for 1 second to ensure the character is fully loaded
  113. Player.CharacterAdded:Connect(function()
  114. ApplyEnemyHighlight()
  115. end)
  116. end
  117.  
  118. -- Apply highlight to all players already in the game
  119. ApplyEnemyHighlight()
  120.  
  121. -- Connect player-added event to ensure new players are handled correctly
  122. Players.PlayerAdded:Connect(OnPlayerAdded)
  123.  
  124. -- Apply highlight when the player's character is added
  125. LocalPlayer.CharacterAdded:Connect(function()
  126. ApplyEnemyHighlight()
  127. end)
  128.  
  129. -- Loop to constantly apply the highlight every 5 seconds using RunService
  130. RunService.Heartbeat:Connect(function()
  131. ApplyEnemyHighlight() -- Reapply the enemy highlights regularly
  132. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement