Getting pivot of model with a primary part not returning correct position

Trying to get the pivot of a model in a viewport frame.

:GetPivot().Position returns 0,0,0 event though in the explorer (clientside) position ~= 0,0,0

Cannot find solution. Tried using serverside and clientside solutions, nothing works so far.

Below is code for clientside script - serverside script can be requested if needed

if fileInstance:GetAttribute("fileId") ~= 0 then
	
	local ViewportFrame = fileInstance:WaitForChild("ViewportFrame")

	task.wait(3)
	
	-- sorts objects into a model (for ease of use)
	local objects = ViewportFrame:GetChildren()
	local Model = Instance.new("Model")
	Model.Parent = ViewportFrame

	for key, object in objects do

		object.Parent = Model
	end

	Model.PrimaryPart = Model:FindFirstChildOfClass("Model").PrimaryPart

	-- Viewportframe code
	local camera = Instance.new("Camera")
	camera.Parent = ViewportFrame

	-- Gets transforms for camera
	local rot, size = Model:GetBoundingBox()
	local tuningMul = 1.25
	local targetPos = Vector3.new(size.X*tuningMul, size.Y, size.Z*tuningMul)

	-- Sets transforms for camera
	camera.CFrame = CFrame.new(targetPos, Vector3.new(Model:GetPivot().Position))
	camera.FieldOfView = 60
	ViewportFrame.CurrentCamera = camera
	-- Done with viewportframe code

	print(camera.CFrame.Position)
end

Pretty sure code works now??? I do not know why but it does.

1 Like

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