Hello. So I was trying to figure out why the wood is showing in the viewport and the others are not, I thought it was maybe possible because the other parts are unions? Do unions just not work in viewport frames?
Inventory script:
local RunService = game:GetService('RunService')
local HTTPService = game:GetService('HttpService')
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local ReplicatedAssets = ReplicatedStorage:WaitForChild('Assets')
local ReplicatedModules = ReplicatedStorage:WaitForChild('Modules')
local ItemsMatrix = require(ReplicatedModules:WaitForChild('Items'))
local RemotesFolder = ReplicatedStorage:WaitForChild('Remotes')
local GetDataRemoteFunction = RemotesFolder:WaitForChild('GetData')
local RemoveItemRemote = RemotesFolder:WaitForChild('RemoveItem')
local Interface = script.Parent
local spinningObjects = {}
local activeData = nil
function Update()
if not activeData then
return
end
local inventoryIDCache = {}
for itemID, quantity in pairs( activeData.Inventory ) do
local itemConfiguration = ItemsMatrix:GetItemFromID(itemID)
if not itemConfiguration then
print("there is not an item configuration")
continue
end
local inventoryFrame = Interface.InventoryFrame:FindFirstChild(itemID)
if not inventoryFrame then
--print(inventoryFrame)
inventoryFrame = script.TemplateItem:Clone()
inventoryFrame.Name = itemID
inventoryFrame.LayoutOrder = quantity
for prop, prop_val in pairs( itemConfiguration.Display.Title ) do
inventoryFrame.Title[prop] = prop_val
--print(inventoryFrame.Title[prop])
end
local modelObject = ReplicatedAssets:FindFirstChild(itemConfiguration.Model)
if modelObject then
modelObject = modelObject:Clone()
if modelObject:IsA('Model') then
modelObject:SetPrimaryPartCFrame(itemConfiguration.Viewport.Model)
elseif modelObject:IsA('BasePart') then
modelObject.CFrame = itemConfiguration.Viewport.Model
else
warn('Unsupported Instance for Model: ' .. modelObject.Name .. ' - ' .. modelObject.ClassName)
end
modelObject.Parent = inventoryFrame.Viewport
table.insert(spinningObjects, modelObject)
local viewportCamera = Instance.new('Camera')
viewportCamera.CFrame = itemConfiguration.Viewport.Camera
inventoryFrame.Viewport.CurrentCamera = viewportCamera
end
inventoryFrame.Clear.Activated:Connect(function()
RemoveItemRemote:FireServer(itemID)
end)
inventoryFrame.Parent = Interface.InventoryFrame
end
local resourcesFrame = script.Parent:WaitForChild('Resources')
inventoryFrame.Quantity.Text = 'x'..quantity
table.insert(inventoryIDCache, itemID)
end
-- destroy any old frames (any inventory items that are removed)
for _, Frame in ipairs(Interface.InventoryFrame:GetChildren()) do
if Frame:IsA('Frame') and not table.find(inventoryIDCache, Frame.Name) then
Frame:Destroy()
end
end
end
local rotationCFrame = CFrame.Angles( 0, math.rad(0.8), 0 )
RunService.Heartbeat:Connect(function()
for i, object in ipairs( spinningObjects ) do
if (not object.Parent) then
table.remove(spinningObjects, i)
break
end
if object:IsA('Model') then
object:SetPrimaryPartCFrame( object:GetPrimaryPartCFrame() * rotationCFrame )
elseif object:IsA('BasePart') then
object.CFrame *= rotationCFrame
end
end
end)
-- get data loop
task.defer(function()
local oldDataJSON = ''
while task.wait(0.25) do
activeData = GetDataRemoteFunction:InvokeServer()
local newData = activeData and HTTPService:JSONEncode(activeData)
if newData ~= oldDataJSON then
oldDataJSON = newData
task.defer(Update)
end
end
end)
Video attached below