I need help with adding a live ViewPortFrame of the player

This is what I have so far but it’s not live, only when I restart the game will it show the items on the player, but I want to show it right away. Is there a way of have a live ViewPort?

Here is my Local Script:

local uis = game:GetService("UserInputService")

local char = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()

local MouseInDisplay, HoldInDisplay = false, false

local currentX

-- Character Display
local VPFcam = Instance.new("Camera"); VPFcam.Parent = script.Parent.ViewportFrame
VPFcam.CFrame = CFrame.new(0,0,0)
script.Parent.ViewportFrame.CurrentCamera = VPFcam

repeat wait(.1) until game:IsLoaded()

char.Archivable = true

local ClonedChar = char:Clone()
local hrp = ClonedChar:WaitForChild("HumanoidRootPart")

ClonedChar.Parent = script.Parent.ViewportFrame.WorldModel
ClonedChar.Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
ClonedChar:SetPrimaryPartCFrame(CFrame.new(Vector3.new(0,0,-9.5),Vector3.new(0,0,0)))


VPFcam.CFrame = CFrame.new(hrp.Position + (hrp.CFrame.LookVector * 5), hrp.Position)

-- Turning Feature
uis.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
		if MouseInDisplay == true then
			HoldInDisplay = true
			currentX = nil
		end
	end
end)

uis.InputEnded:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
		HoldInDisplay = false
	end
end)

script.Parent.ViewportFrame.MouseMoved:Connect(function(X,Y)

	if HoldInDisplay == false then return end

	if currentX then ClonedChar.PrimaryPart.CFrame *= CFrame.fromEulerAnglesXYZ(0,((X-currentX)*.025),0) end

	currentX = X
end)

script.Parent.ViewportFrame.MouseEnter:Connect(function() MouseInDisplay = true end)
script.Parent.ViewportFrame.MouseLeave:Connect(function() MouseInDisplay = false end)

viewport already updates live you’ve gotta add the accessory yourself

from the code you’ve given you don’t have any event or indication for detecting if the player has changed a slot such as their armour

you need an event that detects whenever the player changes one of the slots and then apply it to the cloned humanoid

Sorry I’m really new to coding, how would I go about doing what you’re saying, I’m not sure where to start?

The reason your ViewportFrame isn’t updating live is because you’re cloning the character only once when the game starts. So any gear or armor changes that happen later won’t show up unless you restart the game.

you should to make some remote event or something like “UPDATEVIEWPORTMODEL”

This way, every time the player equips or changes something, the ViewportFrame will refresh in real time and show the new setup — no need to restart the game.

and here is a example for u if you need it

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UpdateViewport = ReplicatedStorage:WaitForChild("UpdateViewport")

UpdateViewport.OnClientEvent:Connect(function()
	-- Remove the previous clone if it exists yea 
	local worldModel = script.Parent.ViewportFrame.WorldModel
	local oldClone = worldModel:FindFirstChild("CharacterClone")
	if oldClone then
		oldClone:Destroy()
	end

	-- Re-clone the updated character
	local player = game.Players.LocalPlayer
	local char = player.Character
	if not char then return end

	char.Archivable = true
	local clonedChar = char:Clone()
	clonedChar.Name = "CharacterClone"

	local hrp = clonedChar:WaitForChild("HumanoidRootPart")
	clonedChar.Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
	clonedChar:SetPrimaryPartCFrame(CFrame.new(Vector3.new(0, 0, -9.5)))

	clonedChar.Parent = worldModel
end)

2 Likes

Ok so am I adding that to my original script because, I used the script you sent alone, and the player isn’t in the viewport? And if I am adding it, where would I place it, like what line?