I am new to using viewportframes and I am having issues displaying objects. I am making an inventory system and I want to display objects in each slot that the object is placed in. When I place the tool in the viewportframe in studio, it works fine. But when I play the game and place the object in the viewportframe, it shows it at a different angle. How do I fix this? I am placing the item in the viewportframe on the serverside btw.
Video displaying the problem:
Serverscript:
local inventoryFolder = player.Inventory
local mainSlotsFolder = inventoryFolder.MainSlots
local hotSlotsFolder = inventoryFolder.HotSlots
local gui = player.PlayerGui.InventoryUI
local mainframe = gui.MainFrame
local inventoryFrame = mainframe.Inventory
local invslotframe = inventoryFrame.SlotFrame
local invhotframe = inventoryFrame.HotbarFrame
local slot_name
if player.Character then
local function createToolPreview(ITEM_TOOl,slotname)
if not invslotframe:FindFirstChild(slotname).Item:FindFirstChildWhichIsA("Tool") then
local tool = ITEM_TOOl:Clone()
tool.PrimaryPart.Anchored = true
tool:SetPrimaryPartCFrame(CFrame.new(0,0,0)*CFrame.Angles(0,45,90))
tool.Parent = invslotframe:FindFirstChild(slotname).Item
end
end
local function placeinslot(slotname)
local slot = mainSlotsFolder:FindFirstChild(slotname)
if not slot:FindFirstChildWhichIsA("Tool") then
item.Parent = slot
slot_name = slotname
elseif slot:FindFirstChildWhichIsA("Tool").ToolSettings.Type.Value == "Resource" and slot:FindFirstChildWhichIsA("Tool").Name == item.Name then
local tool = slot:FindFirstChildWhichIsA("Tool")
local toolamount = tool.ToolSettings.Amount
toolamount.Value += 1
item:Destroy()
end
end
placeinslot("Slot15")
placeinslot("Slot14")
placeinslot("Slot13")
placeinslot("Slot12")
placeinslot("Slot11")
placeinslot("Slot10")
placeinslot("Slot9")
placeinslot("Slot8")
placeinslot("Slot7")
placeinslot("Slot6")
placeinslot("Slot5")
placeinslot("Slot4")
placeinslot("Slot3")
placeinslot("Slot2")
placeinslot("Slot1")
createToolPreview(item,slot_name)