Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local RunService = game:GetService("RunService")
- local frame = script.Parent
- local camera = game.Workspace.CurrentCamera
- local offset, chunkSive, chunkHalfSive, currentX, currentZ
- local players = {}
- local playerGui = frame.ImageLabel
- playerGui.Parent = nil
- local viewportFrame = frame.ViewportFrame
- for i, descendant in ipairs(workspace.Map:GetDescendants()) do
- if descendant:IsA("BasePart") == false then continue end
- local clone = descendant:Clone()
- clone.Parent = viewportFrame
- end
- local viewportCamera = Instance.new("Camera")
- viewportCamera.FieldOfView = 20
- viewportFrame.CurrentCamera = viewportCamera
- local function Update()
- local focusX = camera.Focus.Position.X / chunkSize
- local focusZ = camera.Focus.Position.Z / chunkSize
- local chunkX = math.floor(focusX)
- local chunkZ = math.floor(focusZ)
- local x = focusX % 1
- local z = focusZ % 1
- if currentX ~= chunkX or currentZ ~= chunkZ then
- currentX, currentZ = chunkX, chunkZ
- local position = Vector3.new(chunkX * chunkSize + chunkHalfSize, 0, chunkZ * chunkSize + chunkHalfSize)
- viewportCamera.CFrame = CFrame.lookAt(position + offset, position, -Vector3.zAxis)
- end
- viewportFrame.Position = UDim2.new(1 - x, 0, 1 - z, 0)
- end
- local function SetOffset(value)
- offset = Vector3.new(0,value,0)
- chunkSize = offset.Y * math.tan(math.rad(viewportCamera.FieldOfView) / 2)
- chunkHalfSize = chunkSize / 2
- currentX, currentZ = math.huge, math.huge
- Update()
- end
- local function UpdatePlayers()
- local focusX = camera.Focus.Position.X / chunkSize
- local focusZ = camera.Focus.Position.Z / chunkSize
- for player, gui in ipairs(players) do
- if player.Character == nil then continue end
- local cFrame = player.Character:GetPivot()
- local x = cFrame.Position.X / chunkSize
- local z = cFrame.Position.Z / chunkSize
- gui.Position = UDim2.new(0.5 - focusX + x, 0, 0.5 - focusZ + z, 0)
- end
- end
- local function PlayerAdded(player)
- local gui = playerGui:Clone()
- gui.TextLabel.Text = player.Name
- gui.Parent = frame
- players[player] = gui
- end
- local function PlayerRemoving(player)
- players[player]:Destroy()
- players[player] = nil
- end
- SetOffset(500)
- camera:GetPropertyChangedSignal("Focus"):Connect(Update)
- RunService.RenderStepped:Connect(UpdatePlayers)
- frame.UpButton.Activated:Connect(function()
- SetOffset(offset.Y + 50)
- end)
- frame.DownButton.Activated:Connect(function()
- SetOffset(offset.Y - 50)
- end)
- for i, player in ipairs(game.Players:GetPlayers()) do PlayerAdded(player) end
- game.Players.PlayerAdded:Connect(PlayerAdded)
- game.Players.PlayerRemoving:Connect(PlayerRemoving)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement