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
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