Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make a ViewportFrame of your ROBLOX Character?

Asked by 4 years ago

So I am working on a survival game and for the avatar editor, I needed a 3D Version of the Player. I tried making one but it ended up making the character glitch out of the Frame, And I was wondering how to do that.

0
i'd like to play your survival game, maybe help? sounds fun iuclds 720 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

https://devforum.roblox.com/t/rendering-the-character-with-a-viewportframe/241369/31

Post 31 by Boatbomber please read the problem and check out the script of Boatbomber that you can download (don't forget the credits) https://devforum.roblox.com/uploads/short-url/4g9S29Zwdhdfdpsz4v5pOd7i9vQ.rbxm

Edit: Uploaded new file. This version is faster, uses less CPU, and has fewer edge cases. Works properly with tools. CharacterViewport.rbxm (4.0 KB)

CharacterViewport.rbxm (4.0 KB) This is the link to download from the model. I forgot that I could download it myself and send it to you. Here, put this local script in the startergui:

local player = game.Players.LocalPlayer
local ScreenGui = Instance.new("ScreenGui",player.PlayerGui)
local ViewportFrame = Instance.new("ViewportFrame",ScreenGui)
ViewportFrame.Position = UDim2.new(0, 200,0, 0)
ViewportFrame.Size = UDim2.new(0, 200,0, 200)
ViewportFrame.BackgroundTransparency = 1

--Made from Boatbomber. I just copied it to help someone, so @

--Services
local RunService        = game:GetService('RunService')
local UserInputService  = game:GetService("UserInputService")

--Localize
local instance,newRay   = Instance.new,Ray.new
local v2,v3,cf,udim2    = Vector2.new,Vector3.new,CFrame.new,UDim2.new
local insert,random,abs = table.insert,math.random,math.abs


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


--Basic setup
local ViewPort          = player.PlayerGui.ScreenGui.ViewportFrame

--Settings
local Offset            = cf(0,1,-6)

--Create the viewport camera
local Camera        = instance("Camera")
    ViewPort.CurrentCamera  = Camera

local ValidClasses = {
    ["MeshPart"] = true; ["Part"] = true; ["Accoutrement"] = true;
    ["Pants"] = true; ["Shirt"] = true;
    ["Humanoid"] = true;
}

local function RenderHumanoid(Model, Parent, MainModel)
    local ModelParts = Model:GetDescendants()
    for i=1, #ModelParts do
        local Part      = ModelParts[i]

        if ValidClasses[Part.ClassName] then

            local a         = Part.Archivable
                Part.Archivable = true

            local RenderClone   = Part:Clone()
                Part.Archivable = a

            if Part.ClassName == "MeshPart" or Part.ClassName == "Part" then
                PartUpdater = RunService.Heartbeat:Connect(function()
                    if Part then
                        RenderClone.CFrame = Part.CFrame
                    else
                        RenderClone:Destroy()
                        PartUpdater:Disconnect()
                    end
                end)
            elseif Part:IsA("Accoutrement") then
                PartUpdater = RunService.Heartbeat:Connect(function()
                    if Part then
                        if RenderClone.Handle then
                            RenderClone.Handle.CFrame = Part.Handle.CFrame
                        end
                    else
                        RenderClone:Destroy()
                        PartUpdater:Disconnect()
                    end
                end)
            elseif Part.ClassName == "Humanoid" then
                --Disable all states. We only want it for clothing wrapping, not for stupid @$$ performance issues
                RenderClone:SetStateEnabled(Enum.HumanoidStateType.FallingDown,         false)
                RenderClone:SetStateEnabled(Enum.HumanoidStateType.Running,             false)
                RenderClone:SetStateEnabled(Enum.HumanoidStateType.RunningNoPhysics,    false)
                RenderClone:SetStateEnabled(Enum.HumanoidStateType.Climbing,            false)
                RenderClone:SetStateEnabled(Enum.HumanoidStateType.StrafingNoPhysics,   false)
                RenderClone:SetStateEnabled(Enum.HumanoidStateType.Ragdoll,             false)
                RenderClone:SetStateEnabled(Enum.HumanoidStateType.GettingUp,           false)
                RenderClone:SetStateEnabled(Enum.HumanoidStateType.Jumping,             false)
                RenderClone:SetStateEnabled(Enum.HumanoidStateType.Landed,              false)
                RenderClone:SetStateEnabled(Enum.HumanoidStateType.Flying,              false)
                RenderClone:SetStateEnabled(Enum.HumanoidStateType.Freefall,            false)
                RenderClone:SetStateEnabled(Enum.HumanoidStateType.Seated,              false)
                RenderClone:SetStateEnabled(Enum.HumanoidStateType.PlatformStanding,    false)
                RenderClone:SetStateEnabled(Enum.HumanoidStateType.Dead,                false)
                RenderClone:SetStateEnabled(Enum.HumanoidStateType.Swimming,            false)
                RenderClone:SetStateEnabled(Enum.HumanoidStateType.Physics,             false)
            end

            RenderClone.Parent = Parent
        end 
    end
end


--Let the world load before starting
wait(1)


local function Render()
    ViewPort:ClearAllChildren()
    --Render the character
    local Char = instance("Model")
        Char.Name = ""
        Char.Parent = ViewPort
    RenderHumanoid(Character,Char)
end

--Handle changes
Character.DescendantAdded:Connect(Render)
Character.DescendantRemoving:Connect(Render)

--Initialize
Render()

CameraUpdater = RunService.Heartbeat:Connect(function()
    if Character.HumanoidRootPart then
        Camera.CFrame =  cf(Character.HumanoidRootPart.CFrame:toWorldSpace(Offset).p, Character.HumanoidRootPart.CFrame.p)
    end
end)
0
But i can't find the model and i don't know how to set it up ThanosOfficials 2 — 4y
0
i sendt you the model Eternalove_fan32 188 — 4y
0
Pls, see the new script Eternalove_fan32 188 — 4y
0
PSL Eternalove_fan32 188 — 4y
0
!!!PLS SEE THE NEW SCRIPT AND THX ME!!! Eternalove_fan32 188 — 4y
Ad

Answer this question