Advertisement
oopsrainbow4

MiniMap

Jun 23rd, 2022
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.58 KB | None | 0 0
  1. local RunService = game:GetService("RunService")
  2. local frame = script.Parent
  3. local camera = game.Workspace.CurrentCamera
  4. local offset, chunkSive, chunkHalfSive, currentX, currentZ
  5. local players = {}
  6. local playerGui = frame.ImageLabel
  7. playerGui.Parent = nil
  8.  
  9. local viewportFrame = frame.ViewportFrame
  10. for i, descendant in ipairs(workspace.Map:GetDescendants()) do
  11.     if descendant:IsA("BasePart") == false then continue end
  12.     local clone = descendant:Clone()
  13.     clone.Parent = viewportFrame
  14. end
  15.  
  16. local viewportCamera = Instance.new("Camera")
  17. viewportCamera.FieldOfView = 20
  18. viewportFrame.CurrentCamera = viewportCamera
  19.  
  20. local function Update()
  21.     local focusX = camera.Focus.Position.X / chunkSize
  22.     local focusZ = camera.Focus.Position.Z / chunkSize
  23.     local chunkX = math.floor(focusX)
  24.     local chunkZ = math.floor(focusZ)
  25.     local x = focusX % 1
  26.     local z = focusZ % 1
  27.     if currentX ~= chunkX or currentZ ~= chunkZ then
  28.         currentX, currentZ = chunkX, chunkZ
  29.         local position = Vector3.new(chunkX * chunkSize + chunkHalfSize, 0, chunkZ * chunkSize + chunkHalfSize)
  30.         viewportCamera.CFrame = CFrame.lookAt(position + offset, position, -Vector3.zAxis)
  31.     end
  32.    
  33.     viewportFrame.Position = UDim2.new(1 - x, 0, 1 - z, 0)
  34. end
  35.  
  36. local function SetOffset(value)
  37.     offset = Vector3.new(0,value,0)
  38.     chunkSize = offset.Y * math.tan(math.rad(viewportCamera.FieldOfView) / 2)
  39.     chunkHalfSize = chunkSize / 2
  40.     currentX, currentZ = math.huge, math.huge
  41.     Update()
  42. end
  43.  
  44. local function UpdatePlayers()
  45.     local focusX = camera.Focus.Position.X / chunkSize
  46.     local focusZ = camera.Focus.Position.Z / chunkSize
  47.     for player, gui in ipairs(players) do
  48.         if player.Character == nil then continue end
  49.         local cFrame = player.Character:GetPivot()
  50.         local x = cFrame.Position.X / chunkSize
  51.         local z = cFrame.Position.Z / chunkSize
  52.         gui.Position = UDim2.new(0.5 - focusX + x, 0, 0.5 - focusZ + z, 0)
  53.     end
  54. end
  55.  
  56. local function PlayerAdded(player)
  57.     local gui = playerGui:Clone()
  58.     gui.TextLabel.Text = player.Name
  59.     gui.Parent = frame
  60.     players[player] = gui
  61. end
  62.  
  63. local function PlayerRemoving(player)
  64.     players[player]:Destroy()
  65.     players[player] = nil
  66. end
  67.  
  68. SetOffset(500)
  69.  
  70. camera:GetPropertyChangedSignal("Focus"):Connect(Update)
  71.  
  72. RunService.RenderStepped:Connect(UpdatePlayers)
  73.  
  74. frame.UpButton.Activated:Connect(function()
  75.     SetOffset(offset.Y + 50)
  76. end)
  77.  
  78. frame.DownButton.Activated:Connect(function()
  79.     SetOffset(offset.Y - 50)
  80. end)
  81.  
  82. for i, player in ipairs(game.Players:GetPlayers()) do PlayerAdded(player) end
  83. game.Players.PlayerAdded:Connect(PlayerAdded)
  84. game.Players.PlayerRemoving:Connect(PlayerRemoving)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement