NeonStranger

Realtime Character Viewport (Full Character)

Dec 5th, 2021
1,295
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local OFFSET = CFrame.new(0,2.5,-7)
  2.  
  3. local RunService = game:GetService("RunService")
  4. local UserInputService = game:GetService("UserInputService")
  5.  
  6. local Player = game.Players.LocalPlayer
  7. local Character = Player.Character or Player.CharacterAdded:Wait()
  8. local ViewPort = script.Parent.ViewportFrame
  9. local Camera = Instance.new("Camera")
  10.  
  11. ViewPort.CurrentCamera  = Camera
  12.  
  13. local ValidClasses = {
  14.     ["MeshPart"] = true; ["Part"] = true; ["Accoutrement"] = true;
  15.     ["Pants"] = true; ["Shirt"] = true;
  16.     ["Humanoid"] = true;
  17. }
  18.  
  19. local RenderObjects = table.create(25)
  20.  
  21. local function RemoveObject(Object)
  22.     local Clone = RenderObjects[Object]
  23.     if not Clone then return nil end
  24.  
  25.     RenderObjects[Object] = nil
  26.     if Clone.Parent:IsA("Accoutrement") then
  27.         Clone.Parent:Destroy()
  28.     else
  29.         Clone:Destroy()
  30.     end
  31.  
  32. end
  33.  
  34. local function AddObject(Object)
  35.     if not ValidClasses[Object.ClassName] then
  36.         return nil
  37.     end
  38.  
  39.     local a = Object.Archivable
  40.     Object.Archivable = true
  41.     local RenderClone = Object:Clone()
  42.     Object.Archivable = a
  43.  
  44.     if Object.ClassName == "MeshPart" or Object.ClassName == "Part" then
  45.         RenderObjects[Object] = RenderClone
  46.  
  47.     elseif Object:IsA("Accoutrement") then
  48.         RenderObjects[Object.Handle] = RenderClone.Handle
  49.  
  50.     elseif Object.ClassName == "Humanoid" then
  51.        
  52.         RenderClone:SetStateEnabled(Enum.HumanoidStateType.FallingDown,         false)
  53.         RenderClone:SetStateEnabled(Enum.HumanoidStateType.Running,             false)
  54.         RenderClone:SetStateEnabled(Enum.HumanoidStateType.RunningNoPhysics,    false)
  55.         RenderClone:SetStateEnabled(Enum.HumanoidStateType.Climbing,            false)
  56.         RenderClone:SetStateEnabled(Enum.HumanoidStateType.StrafingNoPhysics,   false)
  57.         RenderClone:SetStateEnabled(Enum.HumanoidStateType.Ragdoll,             false)
  58.         RenderClone:SetStateEnabled(Enum.HumanoidStateType.GettingUp,           false)
  59.         RenderClone:SetStateEnabled(Enum.HumanoidStateType.Jumping,             false)
  60.         RenderClone:SetStateEnabled(Enum.HumanoidStateType.Landed,              false)
  61.         RenderClone:SetStateEnabled(Enum.HumanoidStateType.Flying,              false)
  62.         RenderClone:SetStateEnabled(Enum.HumanoidStateType.Freefall,            false)
  63.         RenderClone:SetStateEnabled(Enum.HumanoidStateType.Seated,              false)
  64.         RenderClone:SetStateEnabled(Enum.HumanoidStateType.PlatformStanding,    false)
  65.         RenderClone:SetStateEnabled(Enum.HumanoidStateType.Dead,                false)
  66.         RenderClone:SetStateEnabled(Enum.HumanoidStateType.Swimming,            false)
  67.         RenderClone:SetStateEnabled(Enum.HumanoidStateType.Physics,             false)
  68.         RenderClone.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
  69.     end
  70.  
  71.  
  72.     return RenderClone
  73. end
  74.  
  75. RunService.Heartbeat:Connect(function()
  76.    
  77.     if (not Character:FindFirstChild("HumanoidRootPart")) or (not ViewPort.Visible) then
  78.         return nil
  79.     end
  80.  
  81.     Camera.CFrame = CFrame.new(Character.HumanoidRootPart.CFrame:ToWorldSpace(OFFSET).Position, Character.HumanoidRootPart.Position)
  82.  
  83.     for Original, Clone in pairs(RenderObjects) do
  84.         if Original and Original.Parent then
  85.             Clone.CFrame = Original.CFrame
  86.         else
  87.             RemoveObject(Original)
  88.         end
  89.     end
  90. end)
  91.  
  92.  
  93. wait(1)
  94.  
  95. local function HandleChar()
  96.  
  97.     table.clear(RenderObjects)
  98.     ViewPort:ClearAllChildren()
  99.  
  100.     local Viewmodel = Instance.new("Model")
  101.     Viewmodel.Name = "PlayerViewmodel"
  102.     Viewmodel.Parent = ViewPort
  103.  
  104.     local CharObjects = Character:GetDescendants()
  105.     for i, Object in pairs(CharObjects) do
  106.         local RenderClone = AddObject(Object)
  107.         if RenderClone then
  108.             RenderClone.Parent = Viewmodel
  109.         end
  110.     end
  111.  
  112.     Character.DescendantAdded:Connect(function(NewObject)
  113.         local RenderClone = AddObject(NewObject)
  114.         if RenderClone then
  115.             RenderClone.Parent = Viewmodel
  116.         end
  117.     end)
  118.     Character.DescendantRemoving:Connect(function(OldObject)
  119.         RemoveObject(OldObject)
  120.     end)
  121. end
  122.  
  123.  
  124. Player.CharacterAdded:Connect(function(NewCharacter)
  125.    
  126.     wait(0.25)
  127.     Character = NewCharacter
  128.     HandleChar()
  129.    
  130. end)
  131.  
  132. HandleChar()
  133.  
RAW Paste Data