How to make a part visible in the GUI but not visible in game to the player

So I am making a GPS system and I want a part (the path of the GPS) to be visible in the viewport frame of my GUI, but not visible to the player in game (or to other players). How would I go to scripting this type of system?

My current script:

local viewportCamera = Instance.new("Camera", game.Workspace)
local RunService = game:GetService("RunService")
local player = game.Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()
local HRP = Character:WaitForChild("HumanoidRootPart")
local viewportFrame = player.PlayerGui:WaitForChild("GPS").Frame.ViewportFrame
local arrow = viewportFrame.Parent.Arrow
local DistanceValue = viewportFrame.Parent.CameraDistance
local location = player.PlayerGui.GPSLocation
local TestGPS = location.Frame.Test

viewportCamera.CameraType = Enum.CameraType.Scriptable
viewportFrame.CurrentCamera = viewportCamera
viewportCamera.FieldOfView = 1

for _, items in pairs(workspace.GPSItems:GetChildren()) do
	local cloneItems = items:Clone()
	if cloneItems:IsA("Model") and cloneItems.Name == "Road" then
		cloneItems.Parent = viewportFrame
	elseif cloneItems:IsA("Model") and cloneItems.Name ~= "Road" then
		cloneItems:Destroy()
	elseif cloneItems:IsA("Part") then
		cloneItems:Destroy()
	elseif cloneItems:IsA("Part") and cloneItems.Name == "TestGPSLocation" then
		print("Location detected")
	end
end

RunService.RenderStepped:Connect(function()
	viewportCamera.CFrame = CFrame.new(HRP.Position + Vector3.new(0,DistanceValue.Value,0), HRP.Position)
end)

DistanceValue.Changed:Connect(function()
	RunService.RenderStepped:Connect(function()
		viewportCamera.CFrame = CFrame.new(HRP.Position + Vector3.new(0,DistanceValue.Value,0), HRP.Position)
	end)
end)

TestGPS.MouseButton1Click:Connect(function()
	local GPath = game:GetService("ReplicatedStorage").TestGPSLocation:Clone()
	GPath.Parent = workspace.GPSItems
end)

You need to parent the GPS part to the ViewportFrame (or some descendant of the viewport frame), rather than the workspace. Your current code is parenting GPath to workspace.GPSItems, which is probably why you can’t see it in your viewport frame at the moment.

You may already be planning for this, but just in case: Since the ViewportFrame really is an entirely separate world space from the workspace, you’ll need separate models for your entire mini-map in there, including independent representations of buildings, roads, etc.

1 Like

You’ll need to make use of a “ViewportFrame” instance to achieve this.

1 Like