Why does viewportframe give wrong position when using WorldToViewportPoint

so as the title says, why does viewportframe give wrong position when using WorldToViewportPoint. I use it to get the position from models in a viewportframe so i can attach gui frames to the exact position of the 3d model instances in it but for some reason it gives a wrong position. The problem may be the viewportframe size itself

how its supposed to be:

how it currently is:


the code:

					
					for _, instance in pairs(itemModel:WaitForChild("Nodes"):GetChildren()) do
						
						if instance.Name == resource and instance:IsA("BasePart") then
						
							local resourceFrame = script.viewport_resource:Clone()
							resourceFrame.Parent = script.Parent  -- Adjust the parent as per your game's structure
							--[[node.Adornee = instance
							node.Enabled = true]]

							local update = function()
							local position = viewport_camera:WorldToViewportPoint(instance.Position)
								--resourceFrame.Position = UDim2.new(0, position.X, 0, position.Y)
								local UIPos = UDim2.new(position.X, 0, position.Y, 0, position.Z, 0)
								resourceFrame.Position = UIPos
								
							end
							
							
							
							local resourceFrame = resourceFrame
							resourceFrame.ResourceName.Text = resource
							resourceFrame.ResourceAmount.Text = "x" .. amount
							
							game:GetService("RunService").RenderStepped:Connect(update)
							
						
						end
					end
				

sorry if there are to much tabs

nevermind! i fixed the problem by parenting the resourceframe to the itemview viewportframe! :laughing:

2 Likes

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