Adding lots of vieuwportFrames

I have this crate spinning effect with in each frame it go’s past a viewportFrame. In the viewportFrame should be an npc, but the function doesn’t work, I tried asking chat gpt but it didn’t help:

local function viewportTower(tower,viewportFrame)
	local towerClone = towerFolder[tower]:Clone()
	towerClone.Parent = viewportFrame

	local camera = Instance.new("Camera")
	camera.Parent = viewportFrame
	viewportFrame.CurrentCamera = camera

	local npcPrimaryPart = towerClone.PrimaryPart or towerClone:FindFirstChildWhichIsA("BasePart")
	
	if npcPrimaryPart then
		camera.CFrame = CFrame.new(npcPrimaryPart.Position + Vector3.new(0, 2, 5), npcPrimaryPart.Position)
	end
end
1 Like

i you trying to make the npc show on the viewportFrame?

or are you trying to make a spining effect.

i think this will work:

local function viewportTower(tower,viewportFrame)
local RS = game:GetService(“RunService”)
local towerClone = towerFolder[tower]:Clone()
local spinSpeed = 1 – How fast you want you Tower to Spin

towerClone.Parent = viewportFrame
RS.Heartbeat:Connect(function()
	towerClone:PivotTo(towerClone:GetPivot() * CFrame.Angles(0, math.rad(spinSpeed), 0))
end)

local camera = Instance.new("Camera")
camera.Parent = viewportFrame
viewportFrame.CurrentCamera = camera

local npcPrimaryPart = towerClone.PrimaryPart or towerClone:FindFirstChildWhichIsA("BasePart")

if npcPrimaryPart then
	camera.CFrame = CFrame.new(npcPrimaryPart.Position + Vector3.new(0, 2, 5), npcPrimaryPart.Position)
end

end

I’m trying to show the npc in the viewport frame

can you give me a screenshot of your viewport frame because it worked for me.

I found the problem, viewport frames don’t work in billboardguis unless it’s located in startegui or the adornee is only set.

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