(FIXED) ViewportFrame doesn't change/Update

Recently I was scripting a ViewportFrame Gui and I can’t change the ObjectValue.Value during playtesting which causes a bug where I can’t change the object being shown while playing

Here is the Local Script

local viewportcamera = Instance.new("Camera",script)
viewportcamera.CameraType = Enum.CameraType.Scriptable

local R = 0

local object = script.Parent.Parent.Frame.Info.Object2.Value

local viewportpoint = Vector3.new(0,0,0)

local viewportframe = script.Parent

viewportframe.CurrentCamera = viewportcamera

object:SetPrimaryPartCFrame(CFrame.new(viewportpoint))

object.Parent = viewportframe

game:GetService("RunService").RenderStepped:Connect(function()


local cframe, size = object:GetBoundingBox()

local max =  math.max(size.X,size.Y,size.Z)

local dis = (max/math.tan(math.rad(viewportcamera.FieldOfView))) * 1.5

local curentdis = (max/2) + dis

	viewportcamera.CFrame = CFrame.Angles(0,math.rad(R),0) * CFrame.new(viewportpoint + Vector3.new(0,0,curentdis),viewportpoint)
	
	R = R + 1 
	
end)

And also a second Local Script where the values are getting changed by on which the button is pressed

local name2 = script.Parent.Parent.Parent.Info.ItemName
local name3 = script.Parent.Parent.Parent.Info.ItemNameText
--//HERE//--
local object = script.Parent.Object
local object2 = script.Parent.Parent.Parent.Info.Object2
--//HERE//--
local stats = script.Parent.Stats
local stats2 = script.Parent.Parent.Parent.Info.Stats2
local stats3 = script.Parent.Parent.Parent.Info.ItemStats
local Item = script.Parent
local description = script.Parent.Description
local description2 = script.Parent.Parent.Parent.Info.Description2
local description3 = script.Parent.Parent.Parent.Info.ItemDescription
local tweenervice  = game:GetService("TweenService")
local Roundframe = script.Parent.Frame
local buy = script.Parent.ItemBuy
local buy2 = script.Parent.Parent.Parent.Info.BuyButton
local buy3 = script.Parent.Parent.Parent.Info.Buy

--// Main //--

script.Parent.MouseButton1Click:connect(function()
	price2.Value = price.Value
	price3.Text = pricefake.Value
	name2.Value = name.Value
	name3.Text = name.Value
	--//HERE//--
	object2.Value = object.Value
	--//HERE//--
	stats2.Value = stats.Value
	stats3.Text = stats.Value
	description2.Value = description.Value
	description3.Text = description.Value
	buy2.Value = buy.Value
	buy3.Text = buy.Value
	
end)
How it works

The player would activate a function (MouseButton1Click) where then it gets the Variable Object and then it makes Object2 have equal value with the Object value and after that, the Viewport script gets the Object2’s value and it should change the object shown, but it stays on nil

The strangest thing is, Object2 is changing its Value, but the Viewport script doesn’t

Update:

I’ve fixed the problem myself so you don’t need to help me anymore on this bug and therefore I’ll abandon this post, but you could still give answers for other people who have encountered the same bug :tongue:

1 Like