Viewport Frames rendering Mesh from script

I am trying to show a mesh inside a Viewport frame. I want to do it via scripting rather than the manual approach. Totally confused by the various types of meshes.

local vf = Instance.new(“ViewportFrame”, script.Parent)
vf.Size = UDim2.new(0.5, 0, 0.5, 0)
vf.Position = UDim2.new(0.25, 0, 0.25, 0)
vf.BackgroundColor3 = Color3.new(1, 1, 1)

local part = Instance.new(“Part”, vf)
part.Position = Vector3.new(0, 0, 0)
part.Anchored = true

local mesh = Instance.new(“MeshPart”, vf)
mesh.Position = Vector3.new(0, 0, 0)
mesh.Anchored = true
–mesh.MeshId = " rbxassetid://152974867" --this breaks the code
–mesh.TextureID = “rbxassetid://152168048”

local camera = Instance.new(“Camera”, vf)
vf.CurrentCamera = camera
local cameraPosition = Vector3.new(3, 3, 3)
camera.CFrame = CFrame.new(cameraPosition, part.Position)

function makeBrickMove()

for i = 1,100 do
wait(.1)
part.CFrame = CFrame.Angles(0,(math.rad(i*10)),0)
end
end

makeBrickMove()

The MeshId and TextureId require an asset link rather than a sole number.
The short version of such links looks like this: rbxassetid://<actual_id>, for example rbxassetid://123.

Regarding the texure ID, make sure you’re using the image ID rather than the decal ID.

Also read what XAXA said. To add on to it, there’s typically a description of the actual error in the console. IIRC, trying to edit a MeshPart’s MeshId actually prints something like “MeshIds cannot be changed at runtime”.

You can’t set the MeshId of a MeshPart using a script. Clone an existing MeshPart or use a Part w/ a SpecialMesh instead.


Also, you can surround your code in ```backticks``` so that it’s more readable.

```
print(“Hello World”)
```

will display

print("Hello World")

Yeah tried that originally, but still has problems.

error message
02:55:51.446 - Unable to assign property MeshId. Script write access is restricted]

Well… like I said:

… If you need a walkthrough on how to do this with a Part/SpecialMesh, you can delete your mesh-making code (side note, you’re not actually rotating the mesh with your code, but the part you created above it) and replace it with this:

local specialMesh = Instance.new("SpecialMesh")
specialMesh.MeshId = "rbxassetid://152974867"
specialMesh.TextureId = "rbxassetid://152974868"
specialMesh.MeshType = Enum.MeshType.FileMesh
specialMesh.Parent = part
1 Like

Thanks, this works great.

local vf = Instance.new(“ViewportFrame”, script.Parent)
vf.Size = UDim2.new(0.5, 0, 0.5, 0)
vf.Position = UDim2.new(0.25, 0, 0.25, 0)
vf.BackgroundColor3 = Color3.new(1, 1, 1)

local part = Instance.new(“Part”, vf)
part.Position = Vector3.new(0, 0, 0)
part.Anchored = true

local specialMesh = Instance.new(“SpecialMesh”)
specialMesh.MeshId = “rbxassetid://152974867”
specialMesh.TextureId = “rbxassetid://2015542122”
specialMesh.MeshType = Enum.MeshType.FileMesh
specialMesh.Parent = part

local camera = Instance.new(“Camera”, vf)
vf.CurrentCamera = camera
local cameraPosition = Vector3.new(3, 3, 3)
camera.CFrame = CFrame.new(cameraPosition, part.Position)

function makeBrickMove()
for i = 1,100 do
wait(.1)
part.CFrame = CFrame.Angles(0,(math.rad(i*10)),0)
end
end

makeBrickMove()