It’s a simple local script where I clone the local player’s character and place it into my viewport frame
However, when trying to access the member “HumanoidRootPart” (which is usually there in all scenarios), it returns an error saying that it is not a valid member like the title above.
Said code is below:
local LocalPlayer = game.Players.LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local ViewCharacter = script.Parent
Character.Archivable = true
local VCChar = Character:Clone()
VCChar.Parent = ViewCharacter
Character.Archivable = false
local HumanoidRootPart: Part = VCChar.HumanoidRootPart or VCChar:WaitForChild('HumanoidRootPart') -- error here
HumanoidRootPart.Anchored = true
HumanoidRootPart.Position = Vector3.zero
local VCCam = Instance.new("Camera")
VCCam.CFrame = CFrame.new(HumanoidRootPart.Position + (HumanoidRootPart.CFrame.LookVector * 3), VCChar.Head.Position)
VCCam.Parent = ViewCharacter
ViewCharacter.CurrentCamera = VCCam
and the Hierarchy is as below:
StarterGui
- CharacterView (ScreenGUI)
-- ViewCharacter (my viewport frame)
--- LoadChar (my local script with the code above)
I have just tried using
local HumanoidRootPart = VCChar:WaitForChild('HumanoidRootPart')
but now the error is:
Infinite yield possible on 'Players.blahblahblah.PlayerGui.CharacterView.ViewCharacter.blahblahblah:WaitForChild("HumanoidRootPart")'
(blahblahblah is the local player’s name btw)
genuinely dunno how to fix this, please help