Advertisement
Paulo87

FleeTheFacility_DistanceTracker

Aug 4th, 2024 (edited)
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.07 KB | None | 0 0
  1. local player = game.Players.LocalPlayer
  2. local playerGui = player:WaitForChild("PlayerGui")
  3. local screenGui = playerGui:WaitForChild("ScreenGui")
  4. local playerNamesFrame = screenGui:WaitForChild("PlayerNamesFrame")
  5.  
  6. local function getBeast()
  7.     local players = game.Players:GetChildren()
  8.     for i = 1, #players do
  9.         if players[i]:FindFirstChild("TempPlayerStatsModule") and players[i].TempPlayerStatsModule:FindFirstChild("IsBeast") and players[i].TempPlayerStatsModule.IsBeast.Value == true or (players[i].Character ~= nil and players[i].Character:FindFirstChild("BeastPowers")) then
  10.             return players[i]
  11.         end
  12.     end
  13.     return nil
  14. end
  15.  
  16. local function updatePlayerDistance(otherPlayer, beast)
  17.     local playerName = otherPlayer.Name
  18.     local playerNameLabel = playerNamesFrame:FindFirstChild(playerName .. "PlayerFrame")
  19.  
  20.     if playerNameLabel then
  21.         local distanceLabel = playerNameLabel:FindFirstChild("DistanceLabel")
  22.  
  23.         if not distanceLabel then
  24.             distanceLabel = Instance.new("TextLabel")
  25.             distanceLabel.Name = "DistanceLabel"
  26.             distanceLabel.Parent = playerNameLabel
  27.             distanceLabel.Size = UDim2.new(0, 60, 1, 0)
  28.             distanceLabel.BackgroundTransparency = 1
  29.             distanceLabel.TextColor3 = Color3.fromRGB(255, 255, 255)
  30.             distanceLabel.TextStrokeTransparency = 0.5
  31.             distanceLabel.TextScaled = true
  32.             distanceLabel.Text = "0"
  33.             distanceLabel.Position = UDim2.new(0, -1, 0, 0)
  34.             distanceLabel.AnchorPoint = Vector2.new(1, 0)
  35.             distanceLabel.Font = Enum.Font.SourceSansBold
  36.             distanceLabel.TextSize = 14
  37.         end
  38.  
  39.         local humanoidRootPart = otherPlayer.Character and otherPlayer.Character:FindFirstChild("HumanoidRootPart")
  40.         if humanoidRootPart then
  41.             local distance = (humanoidRootPart.Position - player.Character.HumanoidRootPart.Position).magnitude
  42.             distanceLabel.Text = math.floor(distance)
  43.            
  44.             if otherPlayer == beast then
  45.                 distanceLabel.TextColor3 = Color3.fromRGB(255, 0, 0)
  46.             else
  47.                 distanceLabel.TextColor3 = Color3.fromRGB(255, 255, 255)
  48.             end
  49.         end
  50.     end
  51. end
  52.  
  53. local function updateAllDistances()
  54.     local beast = getBeast()
  55.     for _, otherPlayer in ipairs(game.Players:GetPlayers()) do
  56.         if otherPlayer ~= player then
  57.             updatePlayerDistance(otherPlayer, beast)
  58.         end
  59.     end
  60. end
  61.  
  62. game.Players.PlayerAdded:Connect(function(otherPlayer)
  63.     updatePlayerDistance(otherPlayer, getBeast())
  64. end)
  65.  
  66. game.Players.PlayerRemoving:Connect(function(otherPlayer)
  67.     local playerFrameName = otherPlayer.Name .. "PlayerFrame"
  68.     local playerFrame = playerNamesFrame:FindFirstChild(playerFrameName)
  69.     if playerFrame then
  70.         local distanceLabel = playerFrame:FindFirstChild("DistanceLabel")
  71.         if distanceLabel then
  72.             distanceLabel:Destroy()
  73.         end
  74.     end
  75. end)
  76.  
  77. game:GetService("RunService").RenderStepped:Connect(updateAllDistances)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement