I have been trying to create a viewport frame that shows a front facing view of the players character. However, no matter what I do the player is not being shown. No errors come up when B is pressed. This is my code so far:
local UIS = game:GetService("UserInputService")
local PLRS = game:GetService("Players")
local Viewport = script.Parent:WaitForChild("INVENTORY"):WaitForChild("BG"):WaitForChild("PlayerModelView")
UIS.InputBegan:Connect(function(input, istyping)
if input.KeyCode == Enum.KeyCode.B and istyping == false then
local Player = PLRS.LocalPlayer
local ViewportCamera = Instance.new("Camera", Viewport)
ViewportCamera.Name = "ViewportCamera"
Viewport.CurrentCamera = ViewportCamera
if not Viewport:FindFirstChild("MODEL_" ..Player.Name) then
local PlayerModelOrigin = Player.Character
PlayerModelOrigin.Archivable = true
local PlayerModel = PlayerModelOrigin:Clone()
PlayerModelOrigin.Archivable = false
PlayerModel.Name = "MODEL_" .. Player.Name
PlayerModel.Parent = Viewport
print(PlayerModel.PrimaryPart.Name)
for _, v in pairs(PlayerModel:GetDescendants()) do
if v:IsA("Script") then
v:Destroy()
end
end
PlayerModel.PrimaryPart.Position = Vector3.new(0, 0, 0)
ViewportCamera.CFrame = CFrame.new((PlayerModel.PrimaryPart.Position + Vector3.new(0, 5, 5)), PlayerModel.PrimaryPart.Position)
else
warn("VIEWPORT MODEL ALREADY EXISTS!: " .. Viewport:FindFirstChild("MODEL_" .. Player.Name).Name)
ViewportCamera.CFrame = CFrame.new(Vector3.new(0, 5, 5), Viewport:FindFirstChild("MODEL_" .. Player.Name).PrimaryPart.Position)
end
end
end)
Any help would be greatly appreciated!