How can I put a part in a viewport frame thing

so what I want to do is make it where when I click on this part it will make the part show up on the screen as a viewport item how can I achieve this?

here’s my code;

 local inspectMechanic = {}

 local player = game.Players.LocalPlayer

 function inspectMechanic:inspect(Target)

print("inspect")

local ViewportGui = Instance.new("ScreenGui", player.PlayerGui)
ViewportGui.Name = "ViewportGui"

local ViewportFrame = game.ReplicatedStorage.gameConfigurations.ViewportFrame
ViewportFrame.Parent = ViewportGui

local ViewportCamera = Instance.new("Camera", player.PlayerGui.ViewportGui)
ViewportCamera.Name = "ViewportCamera"

local inspectItem = game.ReplicatedStorage.gameConfigurations.Part
inspectItem.Parent = ViewportGui

ViewportFrame.CurrentCamera = ViewportCamera


 end

 return inspectMechanic

here’s a video of how it operates so far.

see the black frame I want to be occupied by the part

You’d want to put the part directly into the ViewportFrame, not just the GUI itself.

Aside from that, the other thing you’d want to do is make it so the ViewportFrame’s camera looks toward the part so you can actually see it. You can also set the part’s position to an origin point to make it easier to adjust the camera angle for different models and such; so everything remains consistent.

ViewportCamera.CFrame = CFrame.lookAt(Vector3.new(0, 0, 0), inspectItem.Position)

You might also need to offset the CFrame a bit so you can see the part more clearly.

thanks for your response, I am new to this viewport scripting can you maybe explain where I would insert this line and what you were explaining up there? Because I have no idea about putting the part into the viewport.

 local inspectMechanic = {}

 local player = game.Players.LocalPlayer

 function inspectMechanic:inspect(Target)

print("inspect")

local ViewportGui = Instance.new("ScreenGui", player.PlayerGui)
ViewportGui.Name = "ViewportGui"

local ViewportFrame = game.ReplicatedStorage.gameConfigurations.ViewportFrame
ViewportFrame.Parent = ViewportGui

local ViewportCamera = Instance.new("Camera", player.PlayerGui.ViewportGui)
ViewportCamera.Name = "ViewportCamera"

local inspectItem = game.ReplicatedStorage.gameConfigurations.Part
inspectItem.Parent = ViewportFrame
inspectItem.Position = Vector3.new(0, 0, 0)

ViewportFrame.CurrentCamera = ViewportCamera
ViewportCamera.CFrame = CFrame.lookAt(Vector3.new(0, 0, 5), inspectItem.Position)

 end

 return inspectMechanic
1 Like

Ok thank you and while you’re still here do you have any idea how I could go about making this part rotatable by like when the player holds down right click and moves their mouse?

2 Likes