Pet System Help

  1. What do you want to achieve?

I want to make a pet model show up in a viewport frame

  1. What is the issue?
    When I viewport the model, only one of the part is showing up on the viewport
    image

Here is the viewport frame script:

function ShowViewport(objectName)
	if petsFolder:FindFirstChild(objectName) and holder:FindFirstChild("Camera") then
		if run ~= nil then
			run:Disconnect()
		end
		
		local viewPort = holder.ViewportFrame
		
		if viewPort:FindFirstChildOfClass("Model")then
			viewPort:FindFirstChildOfClass("Model"):Destroy()
		end
		
		viewPort.CurrentCamera = holder.Camera
		local clonedPet = petsFolder:FindFirstChild(objectName):Clone()
		clonedPet.Parent = viewPort
		clonedPet.PrimaryPart.CFrame = holder.Camera.CFrame * CFrame.new(0,0,-3)
		run = RunService.RenderStepped:Connect(function(dt)
			clonedPet.PrimaryPart.CFrame *= CFrame.Angles(0,dt,0)
		end)
	else
	Instance.new("Camera",holder)
	ShowViewport(objectName)
	end
end

Yes, I also welded the parts together using a WeldConstraint

  1. What solutions have you tried so far?

I tried to anchor and unanchor the parts and tried changing the primary part

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

i think the issue would be moving the clonedpet.PrimaryPart.CFrame, since its a model just use clonedpet:SetPrimaryPartCFrame()
in fact you dont even have to cframe the clonedPet just cframe the camera instead.

function ShowViewport(objectName)
	if petsFolder:FindFirstChild(objectName) and holder:FindFirstChild("Camera") then
		if run ~= nil then
			run:Disconnect()
		end
		
		local viewPort = holder.ViewportFrame
		
		if viewPort:FindFirstChildOfClass("Model")then
			viewPort:FindFirstChildOfClass("Model"):Destroy()
		end
		
		viewPort.CurrentCamera = holder.Camera
		local clonedPet = petsFolder:FindFirstChild(objectName):Clone()
		clonedPet.Parent = viewPort
        holder.Camera.CFrame = clonedPet.PrimaryPart.CFrame*CFrame.new(0,0,3)
		--dont need this no more clonedPet.PrimaryPart.CFrame = holder.Camera.CFrame * CFrame.new(0,0,-3)
		run = RunService.RenderStepped:Connect(function(dt)
			--Change this to holder camera cframe instead holder.Camera.CFrame *= CFrame.Angles(0,dt,0)
		end)
	else
	    Instance.new("Camera",holder)
	    ShowViewport(objectName)
	end
end

this is assuming other parts are working the way its intended. (primarypart exists and is oriented correctly in the first place)

Thank you so much for the reply, it works! :slight_smile: