Advertisement
RealLeon

Esp Roblox Script

Dec 1st, 2021
62
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.94 KB | None | 1 0
  1. --[[
  2. A distribution of https://wearedevs.net/scripts
  3. Created August 17, 2021, Last updated August 17, 2021
  4.  
  5. Description: Draws boxes around each player.
  6.  
  7. Credits to "Real Panda" for their ESP library
  8.  
  9. Instruction: Edit the settings as desired below and execute the script.
  10.  
  11. Settings:
  12. Replace "nil" with "true" to enable the setting, or "false" to disable the setting. Without the quotes.
  13. If you do not change "nil", the defaults will take place.
  14. ]]
  15. _G.WRDESPEnabled = nil --Enables the ESP (Defaults to true)
  16. _G.WRDESPBoxes = nil --Draws boxes around other players (Defaults to true)
  17. _G.WRDESPTeamColors = nil --Distinguish different teams by their team color. If the game sets one. (Defaults to true)
  18. _G.WRDESPTracers = nil --Displays lines leading to other players (Defaults to false)
  19. _G.WRDESPNames = nil --Displays the names of the players within the ESP box (Defaults to true)
  20.  
  21. --Dont edit below
  22.  
  23. --Only ever load the script once
  24. if not _G.WRDESPLoaded then
  25. ----[[ First- Load Kiriot ESP Library ]]----
  26.  
  27. --Settings--
  28. local ESP = {
  29. Enabled = false,
  30. Boxes = true,
  31. BoxShift = CFrame.new(0,-1.5,0),
  32. BoxSize = Vector3.new(4,6,0),
  33. Color = Color3.fromRGB(255, 170, 0),
  34. FaceCamera = false,
  35. Names = true,
  36. TeamColor = true,
  37. Thickness = 2,
  38. AttachShift = 1,
  39. TeamMates = true,
  40. Players = true,
  41.  
  42. Objects = setmetatable({}, {__mode="kv"}),
  43. Overrides = {}
  44. }
  45.  
  46. --Declarations--
  47. local cam = workspace.CurrentCamera
  48. local plrs = game:GetService("Players")
  49. local plr = plrs.LocalPlayer
  50. local mouse = plr:GetMouse()
  51.  
  52. local V3new = Vector3.new
  53. local WorldToViewportPoint = cam.WorldToViewportPoint
  54.  
  55. --Functions--
  56. local function Draw(obj, props)
  57. local new = Drawing.new(obj)
  58.  
  59. props = props or {}
  60. for i,v in pairs(props) do
  61. new[i] = v
  62. end
  63. return new
  64. end
  65.  
  66. function ESP:GetTeam(p)
  67. local ov = self.Overrides.GetTeam
  68. if ov then
  69. return ov(p)
  70. end
  71.  
  72. return p and p.Team
  73. end
  74.  
  75. function ESP:IsTeamMate(p)
  76. local ov = self.Overrides.IsTeamMate
  77. if ov then
  78. return ov(p)
  79. end
  80.  
  81. return self:GetTeam(p) == self:GetTeam(plr)
  82. end
  83.  
  84. function ESP:GetColor(obj)
  85. local ov = self.Overrides.GetColor
  86. if ov then
  87. return ov(obj)
  88. end
  89. local p = self:GetPlrFromChar(obj)
  90. return p and self.TeamColor and p.Team and p.Team.TeamColor.Color or self.Color
  91. end
  92.  
  93. function ESP:GetPlrFromChar(char)
  94. local ov = self.Overrides.GetPlrFromChar
  95. if ov then
  96. return ov(char)
  97. end
  98.  
  99. return plrs:GetPlayerFromCharacter(char)
  100. end
  101.  
  102. function ESP:Toggle(bool)
  103. self.Enabled = bool
  104. if not bool then
  105. for i,v in pairs(self.Objects) do
  106. if v.Type == "Box" then --fov circle etc
  107. if v.Temporary then
  108. v:Remove()
  109. else
  110. for i,v in pairs(v.Components) do
  111. v.Visible = false
  112. end
  113. end
  114. end
  115. end
  116. end
  117. end
  118.  
  119. function ESP:GetBox(obj)
  120. return self.Objects[obj]
  121. end
  122.  
  123. function ESP:AddObjectListener(parent, options)
  124. local function NewListener(c)
  125. if type(options.Type) == "string" and c:IsA(options.Type) or options.Type == nil then
  126. if type(options.Name) == "string" and c.Name == options.Name or options.Name == nil then
  127. if not options.Validator or options.Validator(c) then
  128. local box = ESP:Add(c, {
  129. PrimaryPart = type(options.PrimaryPart) == "string" and c:WaitForChild(options.PrimaryPart) or type(options.PrimaryPart) == "function" and options.PrimaryPart(c),
  130. Color = type(options.Color) == "function" and options.Color(c) or options.Color,
  131. ColorDynamic = options.ColorDynamic,
  132. Name = type(options.CustomName) == "function" and options.CustomName(c) or options.CustomName,
  133. IsEnabled = options.IsEnabled,
  134. RenderInNil = options.RenderInNil
  135. })
  136. --TODO: add a better way of passing options
  137. if options.OnAdded then
  138. coroutine.wrap(options.OnAdded)(box)
  139. end
  140. end
  141. end
  142. end
  143. end
  144.  
  145. if options.Recursive then
  146. parent.DescendantAdded:Connect(NewListener)
  147. for i,v in pairs(parent:GetDescendants()) do
  148. coroutine.wrap(NewListener)(v)
  149. end
  150. else
  151. parent.ChildAdded:Connect(NewListener)
  152. for i,v in pairs(parent:GetChildren()) do
  153. coroutine.wrap(NewListener)(v)
  154. end
  155. end
  156. end
  157.  
  158. local boxBase = {}
  159. boxBase.__index = boxBase
  160.  
  161. function boxBase:Remove()
  162. ESP.Objects[self.Object] = nil
  163. for i,v in pairs(self.Components) do
  164. v.Visible = false
  165. v:Remove()
  166. self.Components[i] = nil
  167. end
  168. end
  169.  
  170. function boxBase:Update()
  171. if not self.PrimaryPart then
  172. --warn("not supposed to print", self.Object)
  173. return self:Remove()
  174. end
  175.  
  176. local color
  177. if ESP.Highlighted == self.Object then
  178. color = ESP.HighlightColor
  179. else
  180. color = self.Color or self.ColorDynamic and self:ColorDynamic() or ESP:GetColor(self.Object) or ESP.Color
  181. end
  182.  
  183. local allow = true
  184. if ESP.Overrides.UpdateAllow and not ESP.Overrides.UpdateAllow(self) then
  185. allow = false
  186. end
  187. if self.Player and not ESP.TeamMates and ESP:IsTeamMate(self.Player) then
  188. allow = false
  189. end
  190. if self.Player and not ESP.Players then
  191. allow = false
  192. end
  193. if self.IsEnabled and (type(self.IsEnabled) == "string" and not ESP[self.IsEnabled] or type(self.IsEnabled) == "function" and not self:IsEnabled()) then
  194. allow = false
  195. end
  196. if not workspace:IsAncestorOf(self.PrimaryPart) and not self.RenderInNil then
  197. allow = false
  198. end
  199.  
  200. if not allow then
  201. for i,v in pairs(self.Components) do
  202. v.Visible = false
  203. end
  204. return
  205. end
  206.  
  207. if ESP.Highlighted == self.Object then
  208. color = ESP.HighlightColor
  209. end
  210.  
  211. --calculations--
  212. local cf = self.PrimaryPart.CFrame
  213. if ESP.FaceCamera then
  214. cf = CFrame.new(cf.p, cam.CFrame.p)
  215. end
  216. local size = self.Size
  217. local locs = {
  218. TopLeft = cf * ESP.BoxShift * CFrame.new(size.X/2,size.Y/2,0),
  219. TopRight = cf * ESP.BoxShift * CFrame.new(-size.X/2,size.Y/2,0),
  220. BottomLeft = cf * ESP.BoxShift * CFrame.new(size.X/2,-size.Y/2,0),
  221. BottomRight = cf * ESP.BoxShift * CFrame.new(-size.X/2,-size.Y/2,0),
  222. TagPos = cf * ESP.BoxShift * CFrame.new(0,size.Y/2,0),
  223. Torso = cf * ESP.BoxShift
  224. }
  225.  
  226. if ESP.Boxes then
  227. local TopLeft, Vis1 = WorldToViewportPoint(cam, locs.TopLeft.p)
  228. local TopRight, Vis2 = WorldToViewportPoint(cam, locs.TopRight.p)
  229. local BottomLeft, Vis3 = WorldToViewportPoint(cam, locs.BottomLeft.p)
  230. local BottomRight, Vis4 = WorldToViewportPoint(cam, locs.BottomRight.p)
  231.  
  232. if self.Components.Quad then
  233. if Vis1 or Vis2 or Vis3 or Vis4 then
  234. self.Components.Quad.Visible = true
  235. self.Components.Quad.PointA = Vector2.new(TopRight.X, TopRight.Y)
  236. self.Components.Quad.PointB = Vector2.new(TopLeft.X, TopLeft.Y)
  237. self.Components.Quad.PointC = Vector2.new(BottomLeft.X, BottomLeft.Y)
  238. self.Components.Quad.PointD = Vector2.new(BottomRight.X, BottomRight.Y)
  239. self.Components.Quad.Color = color
  240. else
  241. self.Components.Quad.Visible = false
  242. end
  243. end
  244. else
  245. self.Components.Quad.Visible = false
  246. end
  247.  
  248. if ESP.Names then
  249. local TagPos, Vis5 = WorldToViewportPoint(cam, locs.TagPos.p)
  250.  
  251. if Vis5 then
  252. self.Components.Name.Visible = true
  253. self.Components.Name.Position = Vector2.new(TagPos.X, TagPos.Y)
  254. self.Components.Name.Text = self.Name
  255. self.Components.Name.Color = color
  256.  
  257. self.Components.Distance.Visible = true
  258. self.Components.Distance.Position = Vector2.new(TagPos.X, TagPos.Y + 14)
  259. self.Components.Distance.Text = math.floor((cam.CFrame.p - cf.p).magnitude) .."m away"
  260. self.Components.Distance.Color = color
  261. else
  262. self.Components.Name.Visible = false
  263. self.Components.Distance.Visible = false
  264. end
  265. else
  266. self.Components.Name.Visible = false
  267. self.Components.Distance.Visible = false
  268. end
  269.  
  270. if ESP.Tracers then
  271. local TorsoPos, Vis6 = WorldToViewportPoint(cam, locs.Torso.p)
  272.  
  273. if Vis6 then
  274. self.Components.Tracer.Visible = true
  275. self.Components.Tracer.From = Vector2.new(TorsoPos.X, TorsoPos.Y)
  276. self.Components.Tracer.To = Vector2.new(cam.ViewportSize.X/2,cam.ViewportSize.Y/ESP.AttachShift)
  277. self.Components.Tracer.Color = color
  278. else
  279. self.Components.Tracer.Visible = false
  280. end
  281. else
  282. self.Components.Tracer.Visible = false
  283. end
  284. end
  285.  
  286. function ESP:Add(obj, options)
  287. if not obj.Parent and not options.RenderInNil then
  288. return warn(obj, "has no parent")
  289. end
  290.  
  291. local box = setmetatable({
  292. Name = options.Name or obj.Name,
  293. Type = "Box",
  294. Color = options.Color --[[or self:GetColor(obj)]],
  295. Size = options.Size or self.BoxSize,
  296. Object = obj,
  297. Player = options.Player or plrs:GetPlayerFromCharacter(obj),
  298. PrimaryPart = options.PrimaryPart or obj.ClassName == "Model" and (obj.PrimaryPart or obj:FindFirstChild("HumanoidRootPart") or obj:FindFirstChildWhichIsA("BasePart")) or obj:IsA("BasePart") and obj,
  299. Components = {},
  300. IsEnabled = options.IsEnabled,
  301. Temporary = options.Temporary,
  302. ColorDynamic = options.ColorDynamic,
  303. RenderInNil = options.RenderInNil
  304. }, boxBase)
  305.  
  306. if self:GetBox(obj) then
  307. self:GetBox(obj):Remove()
  308. end
  309.  
  310. box.Components["Quad"] = Draw("Quad", {
  311. Thickness = self.Thickness,
  312. Color = color,
  313. Transparency = 1,
  314. Filled = false,
  315. Visible = self.Enabled and self.Boxes
  316. })
  317. box.Components["Name"] = Draw("Text", {
  318. Text = box.Name,
  319. Color = box.Color,
  320. Center = true,
  321. Outline = true,
  322. Size = 19,
  323. Visible = self.Enabled and self.Names
  324. })
  325. box.Components["Distance"] = Draw("Text", {
  326. Color = box.Color,
  327. Center = true,
  328. Outline = true,
  329. Size = 19,
  330. Visible = self.Enabled and self.Names
  331. })
  332.  
  333. box.Components["Tracer"] = Draw("Line", {
  334. Thickness = ESP.Thickness,
  335. Color = box.Color,
  336. Transparency = 1,
  337. Visible = self.Enabled and self.Tracers
  338. })
  339. self.Objects[obj] = box
  340.  
  341. obj.AncestryChanged:Connect(function(_, parent)
  342. if parent == nil and ESP.AutoRemove ~= false then
  343. box:Remove()
  344. end
  345. end)
  346. obj:GetPropertyChangedSignal("Parent"):Connect(function()
  347. if obj.Parent == nil and ESP.AutoRemove ~= false then
  348. box:Remove()
  349. end
  350. end)
  351.  
  352. local hum = obj:FindFirstChildOfClass("Humanoid")
  353. if hum then
  354. hum.Died:Connect(function()
  355. if ESP.AutoRemove ~= false then
  356. box:Remove()
  357. end
  358. end)
  359. end
  360.  
  361. return box
  362. end
  363.  
  364. local function CharAdded(char)
  365. local p = plrs:GetPlayerFromCharacter(char)
  366. if not char:FindFirstChild("HumanoidRootPart") then
  367. local ev
  368. ev = char.ChildAdded:Connect(function(c)
  369. if c.Name == "HumanoidRootPart" then
  370. ev:Disconnect()
  371. ESP:Add(char, {
  372. Name = p.Name,
  373. Player = p,
  374. PrimaryPart = c
  375. })
  376. end
  377. end)
  378. else
  379. ESP:Add(char, {
  380. Name = p.Name,
  381. Player = p,
  382. PrimaryPart = char.HumanoidRootPart
  383. })
  384. end
  385. end
  386. local function PlayerAdded(p)
  387. p.CharacterAdded:Connect(CharAdded)
  388. if p.Character then
  389. coroutine.wrap(CharAdded)(p.Character)
  390. end
  391. end
  392. plrs.PlayerAdded:Connect(PlayerAdded)
  393. for i,v in pairs(plrs:GetPlayers()) do
  394. if v ~= plr then
  395. PlayerAdded(v)
  396. end
  397. end
  398.  
  399. game:GetService("RunService").RenderStepped:Connect(function()
  400. cam = workspace.CurrentCamera
  401. for i,v in (ESP.Enabled and pairs or ipairs)(ESP.Objects) do
  402. if v.Update then
  403. local s,e = pcall(v.Update, v)
  404. if not s then warn("[EU]", e, v.Object:GetFullName()) end
  405. end
  406. end
  407. end)
  408.  
  409. ----[[ Now Begins WRD's modification for implementation ]]----
  410.  
  411. --Sets defaults where required
  412. if _G.WRDESPEnabled == nil then _G.WRDESPEnabled = true end
  413. if _G.WRDESPBoxes == nil then _G.WRDESPBoxes = true end
  414. if _G.WRDESPTeamColors == nil then _G.WRDESPTeamColors = true end
  415. if _G.WRDESPTracers == nil then _G.WRDESPTracers = false end
  416. if _G.WRDESPNames == nil then _G.WRDESPNames = true end
  417.  
  418. --Hacky way to keep up with setting changes
  419. while wait(.1) do
  420. ESP:Toggle(_G.WRDESPEnabled or false)
  421. ESP.Boxes = _G.WRDESPBoxes or false
  422. ESP.TeamColors = _G.WRDESPTeamColors or false
  423. ESP.Tracers = _G.WRDESPTracers or false
  424. ESP.Names = _G.WRDESPNames or false
  425. end
  426.  
  427. _G.WRDESPLoaded = true
  428. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement