A Question on Viewport Frames

Hey everyone,

I’ve been working on a car game for a little bit now, and I’ve always wanted to upgrade the vehicle spawning UI to include a viewport frame of the car. Unfortunately, though, I’ve never really found a method to get a working viewport frame.

So, I’m wondering how you can use a viewport frame to view a vehicle in a UI?

An example:

Thanks for your help!

1 Like

Please look around before posting. If this was helpful please mark me as solution thanks John.

https://devforum.roblox.com/t/3d-gui-module/5183

1 Like

@Strongjohnfgamer

That is a very outdated solution to this problem and not what OP should be doing here.


@A_roxn

The DevHub has a very helpful article on ViewportFrames that will guide you through how to set one up. You should be able to use this information to create the effect you want.

https://developer.roblox.com/en-us/articles/viewportframe-gui

2 Likes

Thank you, I’ll give it a go.

30 characters

1 Like

So, I’ve run into a problem. The vehicle appears extremely small on the ViewportFrame.

Code
local viewportFrame = Instance.new("ViewportFrame")
viewportFrame.Size = UDim2.new(0.3, 0, 0.4, 0)
viewportFrame.Position = UDim2.new(0, 15, 0, 15)
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
 
local part = script.taxi
part.Parent = viewportFrame
part.Name = "taxi"
part.PrimaryPart = part.DriveSeat
part:SetPrimaryPartCFrame(Vector3.new(0, 0, 0))
 
local viewportCamera = Instance.new("Camera")
viewportFrame.CurrentCamera = viewportCamera
viewportCamera.Parent = viewportFrame
 
viewportCamera.CFrame = CFrame.new(Vector3.new(0, 0, -12), part.DriveSeat.Position)

Can you help me figure out what I’m doing wrong?

1 Like

You should be seeing an error in your console from this line.

SetPrimaryPartCFrame should be called with a CFrame, not a Vector3.

2 Likes

I made a little tutorial on previewing models in ViewportFrames, you can check it out if you want: Previewing items in a ViewportFrame

2 Likes

Another question:

I’m a little scared about an exploiter’s ability to steal my vehicle models when I send them to the client for the ViewportFrame.

Do you know any ways to, protect, for lack of a better term, the models that I am using in the ViewportFrame?

I understand your concern, but I’m still a bit of a beginner on ViewportFrames and don’t really know the ins and outs of them. Of course, anything that is viewable by the client can be stolen by said client, and there is little that can be done about that.

I’m not sure how you would be able to protect your models. You could try and display either a more simplified version of the car or a mesh of it so that the content that could be stolen is much less valuable.

I’ve been concerned about this too but it’s impossible to prevent almost, anything the client can see, even if loaded/spawned in by the server can technically be stolen, all it needs is the client being able to see it, if it’s not in ServerStorage or ServerScriptStorage the player can already see it.

But I personally think the scripts are most important, I rather protect my code than the models, if you hide a model, sure the client can’t steal it, but you won’t be able to use it either, models are made to be seen by the client.

But I woudn’t worry too much about it even if it would get stolen, you’re the original creator of it anyway, it’s not like someone is gonna make lots of profit out of a stolen asset or anything plus you can report this to Roblox if you caught someone.

1 Like

You’re right - completely forgot that the cars being in the workspace is enough for them to get stolen as well.

Thank you so much for your help!

2 Likes