Can someone tell me why this isn't working?

I have this script here for a localscript, but I have no idea why this isn’t working as intended?
Can someone tell me the reason to why?

local ViewportPart ="ScreenGui")
local Main ="Frame")
local Port ="ViewportFrame")
local UIAspectRatioConstraint ="UIAspectRatioConstraint")
ViewportPart.Name = "ViewportPart"
ViewportPart.Parent = game.Players.LocalPlayer:WaitForChild("PlayerGui")
Main.Name = "Main"
Main.Parent = ViewportPart
Main.AnchorPoint =, 0.5)
Main.BackgroundColor3 = Color3.fromRGB(0, 0, 0)
Main.BackgroundTransparency = 0.500
Main.BorderSizePixel = 0
Main.Position =, 0, 0.5, 0)
Main.Size =, 159, 0, 159)
Port.BackgroundTransparency = 1.000
Port.AnchorPoint =, 0.5)
Port.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
Port.BorderSizePixel = 0
Port.BorderColor3 = Color3.fromRGB(27, 42, 53)
Port.Name = "Port"
Port.Parent = Main
Port.Position =, 0, 0.5, 0)
Port.ZIndex = 1
UIAspectRatioConstraint.Parent = Port
local viewportcamera ="Camera",Port)
viewportcamera.CameraType = Enum.CameraType.Scriptable
local yintager = .4
local xintager = 2
local r = 0
local item ="Model")
local itempart ="Part",item)
item.PrimaryPart = itempart
local viewportpoint =,0,0)
local viewportframe = Port
viewportframe.CurrentCamera = viewportcamera
item.Parent = viewportframe
	local cfrane, size = item:GetBoundingBox()
	local max = math.max(size.X,size.Y,size.Z)
	local distance = (max/math.tan(math.rad(viewportcamera.FieldOfView))) * xintager
	local currentdistance = (max/2) + distance
	viewportcamera.CFrame = CFrame.Angles(0,math.rad(r),0) * +,(currentdistance*yintager),currentdistance),viewportpoint)
	r = r +1
print("Spinning part thing")
1 Like

i think i believe the PlayerGui spawns more quicker than the script itself since it is one of the core components

I don’t think so, I tried adding a delay but still nothing.

what does the output sussily say

Is this in a local script? game.Players.LocalPlayer is only accessible through a local script.

Yeah, this is inside a localscript.

Literally nothing at all, which doesn’t help me much.

If you put this script as a localscript in the startergui then it will create the screengui and frame. You can’t create things into the playergui from the localplayer so if you have a way of getting the player the you don’t have to put it in the startergui. Then again, you have to use another way to get the playergui other than localplayer.

Edit - I deleted the script below because when you put it in a script in Roblox it would show up as wrong because the “” showed as wrong.

Unfortunately this still hasn’t fixed the issue I am having.

Is the issue getting the part to spin?

The issue is getting the part to even render into the viewport frame.

It is supposed to look like this:

But the outcome is this: