Viewportframe showing tool at wrong angle

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)
1 Like

have you tried putting the item in the slot through a local script?

1 Like

Yes I have tried and it had the same result or didn’t show up at all.

try instead of putting the clone of the object in the frame, just put the item itself?

I am keeping track of the original item in a folder under the player for the inventory system, which is why I have to create a clone of the object and put it under the viewport frame. I don’t think using the original item would make a difference anyway.

check the pivot of the tool, maybe thats the problem

Perhaps you could simply use a fixed cframe after cloning the object into the preview (and for different item types have different cframe values perhaps)

1 Like

I tried not setting a CFrame and put the object at the center of the world and the preview looks fine. Looks like the problem may be with the CFrame. I’ll look into the pivot.

Looks like the problem was the :SetPrimaryPartCFrame() line. It was giving me weird angles on the tool because I wasn’t using math.rad(). I also switch over from making the preview on the server side to client side(that shouldn’t change anything but I did it anyway).

Fixed line of code:

tool:SetPrimaryPartCFrame(CFrame.new(0,0,0)*CFrame.Angles(math.rad(0),math.rad(45),math.rad(90)))

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.