I’ve been trying for a while now to get the
player character in the GUI! I have experimented a bit with viewport frames but the only way to display the character is to clone it! But I also want to show what the player is doing. Something like in “Entry Point”. I tried to just refresh the player again per frame, which works but takes a lot of power. In addition, I think that the script could be improved!
I have already worked with viewportframes, but I want to show the player in his current form (Example: If the player equips a tool, the clone in the gui should do that too).
I made a basic one a couple of days ago, i can share it with you. As @Vibe90K said, you are cloning your character into a viewport frame every frame.
local viewPortFrame = script.Parent:WaitForChild("ViewportFrame")
local char = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
char.Archivable = true
local newCamera = Instance.new("Camera")
newCamera.Parent = viewPortFrame
viewPortFrame.CurrentCamera = newCamera
local clonedChar
game:GetService("RunService").RenderStepped:Connect(function()
if clonedChar then clonedChar:Destroy() end
clonedChar = char:Clone()
local hrp = clonedChar:WaitForChild("HumanoidRootPart")
newCamera.CFrame = CFrame.new(hrp.Position + (hrp.CFrame.LookVector * 6) + Vector3.new(0,2,0) + (hrp.CFrame.RightVector * 2), hrp.Position)
--I fiddled around with the position of the camera so you get a little bit of a side on view.
clonedChar.Parent = viewPortFrame
end)
My way shows the tools in the GUI, but i guess if you want the camera facing the way your character is in the provided image you should change the camera position to this:
@boatbomber made a script similar to what you are looking for. His script currently doesn’t display tools, but I am sure you can change that by modifying it!
I downloaded your script, tested it with 3 different tools and they were all not displayed in the ViewPortFrame. Maybe this is a problem coming from me, apologies!
Late reply. However i would like to post this here for future viewers:
For anyone using Arlenox’s script from that post, your tool may not show up properly if it is made of unions.
The script does not replicate the UnionOperation class into the viewport, only meshes, and parts (aswell as other stuff)
Heres an edited version which includes UnionOperations:
--[=[
Character Viewport
Realtime viewing oneself in a GUI window, including tools
boatbomber, 2/17/19 (Updated: 6/13/2021)
--]=]
-- Settings
local OFFSET = CFrame.new(2,2.5,-4)
-- Services
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
-- Objects
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local ViewPort = script.Parent.ViewportFrame
local Camera = Instance.new("Camera")
ViewPort.CurrentCamera = Camera
local ValidClasses = {
["MeshPart"] = true; ["Part"] = true; ["UnionOperation"] = true; ["Accoutrement"] = true;
["Pants"] = true; ["Shirt"] = true;
["Humanoid"] = true;
}
local RenderObjects = table.create(25)
local function RemoveObject(Object)
local Clone = RenderObjects[Object]
if not Clone then return nil end
RenderObjects[Object] = nil
if Clone.Parent:IsA("Accoutrement") then
Clone.Parent:Destroy()
else
Clone:Destroy()
end
--print("Removed",Object)
end
local function AddObject(Object)
if not ValidClasses[Object.ClassName] then
return nil
end
-- Create clone, regardless of Archivable
local a = Object.Archivable
Object.Archivable = true
local RenderClone = Object:Clone()
Object.Archivable = a
if Object.ClassName == "MeshPart" or Object.ClassName == "Part" or Object.ClassName == "UnionOperation" then
RenderObjects[Object] = RenderClone
elseif Object:IsA("Accoutrement") then
RenderObjects[Object.Handle] = RenderClone.Handle
elseif Object.ClassName == "Humanoid" then
--Disable all states. We only want it for clothing wrapping.
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)
RenderClone.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
end
--print("Added",Object)
return RenderClone
end
RunService.Heartbeat:Connect(function()
if (not Character:FindFirstChild("HumanoidRootPart")) or (not ViewPort.Visible) then
return nil
end
-- Update camera
Camera.CFrame = CFrame.new(Character.HumanoidRootPart.CFrame:ToWorldSpace(OFFSET).Position, Character.HumanoidRootPart.Position)
-- Update objects
for Original, Clone in pairs(RenderObjects) do
if Original and Original.Parent then
Clone.CFrame = Original.CFrame
else
RemoveObject(Original)
end
end
end)
--Let the world load before starting
wait(1)
local function HandleChar()
--warn("Handle char")
table.clear(RenderObjects)
ViewPort:ClearAllChildren()
local Viewmodel = Instance.new("Model")
Viewmodel.Name = "PlayerViewmodel"
Viewmodel.Parent = ViewPort
local CharObjects = Character:GetDescendants()
for i, Object in pairs(CharObjects) do
local RenderClone = AddObject(Object)
if RenderClone then
RenderClone.Parent = Viewmodel
end
end
Character.DescendantAdded:Connect(function(NewObject)
local RenderClone = AddObject(NewObject)
if RenderClone then
RenderClone.Parent = Viewmodel
end
end)
Character.DescendantRemoving:Connect(function(OldObject)
RemoveObject(OldObject)
end)
end
--Render the character
Player.CharacterAdded:Connect(function(NewCharacter)
wait(0.25) -- wait for character to finish loading
Character = NewCharacter
HandleChar()
end)
HandleChar()