How to make real time viewport

i’m trying to make a delivery map system for my game, but i’ve encountered a problem. for the viewport frame, it only renders once, so new parts doesn’t load in. i tried a few things but i still am a bit confused on this.

I would really appreciate any solutions to this. Thanks in advance.

(current script)

local rs = game:GetService("RunService")
local uis = game:GetService("UserInputService")

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hrp = char:WaitForChild("HumanoidRootPart")

local frame = script.Parent
local arrow = frame.arrow

local inside = false
local zoomLevel = 2000
local zoomStep = 200

local ContextActionService = game:GetService("ContextActionService")
local DisableScroll = false

local cam = Instance.new("Camera")
cam.CameraType = Enum.CameraType.Scriptable
frame.CurrentCamera = cam
cam.FieldOfView = 1


for _, item in pairs(workspace:GetChildren()) do
	if item:IsA("Part") then
		local c = item:Clone()
		c.Parent = frame
	end
end

local function updateCamera()
	cam.CFrame = CFrame.new(hrp.Position + Vector3.new(0, zoomLevel, 0), hrp.Position)
	arrow.Rotation = hrp.Orientation.Y - 90
end

frame.MouseEnter:Connect(function()
	inside = true
end)

frame.MouseLeave:Connect(function()
	inside = false
end)

uis.InputChanged:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseWheel and inside then
		zoomLevel = math.clamp(zoomLevel - (input.Position.Z * zoomStep), 500, 5000) 
		arrow.UIScale.Scale = zoomLevel / 4000
		updateCamera()
	end
end)

rs.RenderStepped:Connect(function()
	updateCamera()
	DisableScroll = inside
end)

ContextActionService:BindAction("DisableScroll",
	function ()
		return DisableScroll and Enum.ContextActionResult.Sink or Enum.ContextActionResult.Pass
	end, false, Enum.UserInputType.MouseWheel)

You need to reupdate the viewport frame everytime a new child is added, you can use game.Workspace.DecendantAdded and then clone the new instance to the viewport frame

i tried it and it works well, but quick question, will the client lag/take a huge load from the continuous cloning, (if it does, is there any other way to do it?)

ty for your reply btw, it helped a lot

Well depends, if a lot of parts gets added and theyre heavy and contains many triangels maybe but it also depends on the clients game graphic settings and their device but you can always add a task.wait() to stop it from lagging too much

ok thanks for the help.
(char limit)

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.