Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

how do you script a "Model" on a viewport frame in SurfaceGui?

Asked by 2 years ago

I used this code to put a single part on a surfacegui and it worked:

local viewportFrame = Instance.new("ViewportFrame")
viewportFrame.Size = UDim2.new(1, 0, 1, 0)
viewportFrame.Position = UDim2.new(0, 0, 0, 0)
viewportFrame.BackgroundColor3 = Color3.new(0, 0, 0)
viewportFrame.BorderColor3 = Color3.new(0.6, 0.5, 0.4)
viewportFrame.BorderSizePixel = 2
viewportFrame.BackgroundTransparency = 0.25
viewportFrame.Parent = script.Parent.CardFrame.Element.Picture
local part = Instance.new("Part")

part.Material = Enum.Material.Concrete
part.BrickColor = BrickColor.new("Bright blue")
part.Position = Vector3.new(0,0,0)
part.Parent = viewportFrame

local viewportCamera = Instance.new("Camera")
viewportFrame.CurrentCamera = viewportCamera
viewportCamera.Parent = viewportFrame

viewportCamera.CFrame = CFrame.new(Vector3.new(0,2,12), part.Position)

but once i put a model in the viewport, it wont work.

local viewportFrame = Instance.new("ViewportFrame")
viewportFrame.Size = UDim2.new(1, 0, 1, 0)
viewportFrame.Position = UDim2.new(0, 0, 0, 0)
viewportFrame.BackgroundColor3 = Color3.new(0, 0, 0)
viewportFrame.BorderColor3 = Color3.new(0.6, 0.5, 0.4)
viewportFrame.BorderSizePixel = 2
viewportFrame.BackgroundTransparency = 0.25
viewportFrame.Parent = script.Parent.CardFrame.Element.Picture
--local part = Instance.new("Part")
local part = game.Workspace.Dummy:Clone()
--part.Material = Enum.Material.Concrete
--part.BrickColor = BrickColor.new("Bright blue")
--part.Position = Vector3.new(0,0,0)
part.Parent = viewportFrame

local viewportCamera = Instance.new("Camera")
viewportFrame.CurrentCamera = viewportCamera
viewportCamera.Parent = viewportFrame

viewportCamera.CFrame = CFrame.new(Vector3.new(0,2,12), part.Head.Position)

does anyone know what i did wrong ?

0
oh wait, i think i figured out te problem rupertrosse 39 — 2y
1
Mark your answer so everybody knows. Antelear 185 — 2y
0
i dont know how, ill let the mods do the job or tell me how rupertrosse 39 — 2y

1 answer

Log in to vote
0
Answered by 2 years ago

i solved the problem, it seems that i made a problem on line 20.

viewportCamera.CFrame = CFrame.new(Vector3.new(0,2,12), part.Head.Position)

I changed it to:

viewportCamera.CFrame = CFrame.new(part.Head.Position + Vector3.new(0,2,12), part.Head.Position)
Ad

Answer this question