-
I want my viewport frame to continue showing the player even when a bundle is added to the player.
-
When I add a bundle to the player, the viewport frame is broken, and doesn’t show anything(Ignore bad UI, it’s just a placeholder): Video of Issue
Viewport frame is the right half of screen. -
I added a loop to the viewport frame to continuously update the frame, it worked, but the frame was constantly glitchy and looked bad.
Code
-- Server Script, adds bundle to player
local bundleDetails = game:GetService("AssetService"):GetBundleDetailsAsync(952)
local bundleId = 0
for _,item in pairs(bundleDetails.Items) do
if item.Type == "UserOutfit" then
bundleId = item.Id
break
end
end
local descr = game.Players:GetHumanoidDescriptionFromOutfitId(bundleId)
player.Character.Humanoid:ApplyDescription(descr)
--Local Script, the viewport frame is edited here
local viewPortFrame = script.Parent
local char = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
char.Archivable = true
local newCamera = Instance.new("Camera")
newCamera.Parent = viewPortFrame
viewPortFrame.CurrentCamera = newCamera
local clonedChar
game:GetService("RunService").RenderStepped:Connect(function()
if clonedChar then clonedChar:Destroy() end
clonedChar = char:Clone()
local hrp = clonedChar:WaitForChild("HumanoidRootPart")
newCamera.CFrame = CFrame.new(hrp.Position + (hrp.CFrame.LookVector * 6) + Vector3.new(0,2,0) + (hrp.CFrame.RightVector * 2), hrp.Position)
clonedChar.Parent = viewPortFrame
end)