Character viewer messes with Viewmodel

I want to make a character display in the middle of the GUI. I used viewport in this tutorial and here is the code

local vpf = script.Parent:WaitForChild("CharacterVPF")
 
local char = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
char.Archivable = true
 
local cam = Instance.new("Camera")
cam.Parent = vpf
 
vpf.CurrentCamera = cam
 
local clonedChar

game:GetService("RunService").RenderStepped:Connect(function()
    if clonedChar then clonedChar:Destroy() end
    clonedChar = char:Clone()
    local hrp = clonedChar:WaitForChild("HumanoidRootPart")
    cam.CFrame = CFrame.new(hrp.Position + (hrp.CFrame.LookVector * 5), hrp.Position)
    clonedChar.Parent = vpf
end)

THIS CODE IS NOT MINE

How do I make one that doesn’t mess with the Viewmodel? By messing with the viewmodel i mean when the viewmodel is activated, it got cloned a lot of time as long as the viewmodel is activated

Please help me.

Why Exactly are you using a RenderStepped? You just need to do that thing once and RenderStepped means you’re constantly updating something (in this case, you’re doing everything again and again forever)

local vpf = script.Parent:WaitForChild("CharacterVPF")
local char = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
char.Archivable = true

local cam = Instance.new("Camera")
cam.Parent = vpf

vpf.CurrentCamera = cam

local clonedChar
if clonedChar then clonedChar:Destroy() end
clonedChar = char:Clone()
local hrp = clonedChar:WaitForChild("HumanoidRootPart")
cam.CFrame = CFrame.new(hrp.Position + (hrp.CFrame.LookVector * 5), hrp.Position)
clonedChar.Parent = vpf

--> REMOVE THIS
--game:GetService("RunService").RenderStepped:Connect(function()

--end)
1 Like

does not work without RunService. Infinite yield on "clonedChar:WaitForChild(“HumanoidRootPart”)

Also, It results in this when using renderstepped and after viewmodel is activated.

cheshnut.HumanoidRootPart:WaitForChild("Running")

What is this error?

That is because you’re probably not getting character itself. Print cloned character and you’ll get nil.

To fix, when you’re first trying to get character do:

local Character = player.Character or player.CharacterAdded:Wait()

Your error means that you’re not properly referencing the HumanoidRootPart
Your last error is because you’re trying to find something called Running in your code, you tell me

I did the first one, still didn’t work

I researched and I found out that HumanoidRootPart is trying to get the sound effect called “Running”

I checked the playerGUI, Find the player model, check humanoidrootpart and the sound effect is not there.

I created a new project and test the script, worked perfectly fine. I think it’s due to the amount of Background scripts running in the game

FYI : HumanoidRootPart waiting for Running sound effect is built into roblox so I can’t change it.