I’ve been trying to create snapshots of maps using ViewportFrames to make it easier to copy and paste maps in for a voting system.
Everything seems to work fine (no errors), but the viewport only displays the background.
The parts and camera are also inside of the ViewportFrame, with the camera attached to the ViewportFrame.
I’ve looked through many solutions but I can’t find any. When testing, I used a script in workspace which worked ok, so I moved it to where I wanted, on the client-side, which made it stop working.
Code:
local MapsFolder = game.ReplicatedStorage.Maps
game.ReplicatedStorage.Remotes.LinkSurfaceGui.OnClientEvent:Connect(function(pad, MapName)
if pad == nil and MapName == nil then
for _, sgui in pairs(game.Players.LocalPlayer.PlayerGui:GetChildren()) do
sgui:Destroy()
end
return
end
local MapModel = MapsFolder:FindFirstChild(MapName)
if not MapModel then
print("map model doesn't exist: "..MapName)
return
end
local focusCF = MapModel.Focus.CFrame
local surfacegui = Instance.new("SurfaceGui")
surfacegui.Face = Enum.NormalId.Top
local thumbnail = Instance.new("ViewportFrame")
thumbnail.Name = "Thumbnail"
thumbnail.Size = UDim2.fromScale(1, 1)
thumbnail.Position = UDim2.fromScale(0, 0)
for _, part in pairs(MapModel:GetChildren()) do
part:Clone().Parent = thumbnail
end
thumbnail.Parent = surfacegui
print(surfacegui.Name)
for _,v in pairs(surfacegui:GetChildren()) do
print(v.Name)
end
local camera = Instance.new("Camera")
thumbnail.CurrentCamera = camera
camera.Parent = surfacegui.Thumbnail
camera.CFrame = focusCF
surfacegui.Adornee = pad
surfacegui.Parent = game.Players.LocalPlayer.PlayerGui
end)