Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I make an avatar appear on a ViewportFrame? [SOLVED]

Hello! I am trying to make a head appear on a screen, just like in Doom. (No: I am not recreating Doom in Roblox) For some reason, whenever I set a variable to the player's cloned character, it always resets itself to nil!

Here's my script which is called "1":

local cam = Instance.new("Camera", script.Parent)
cam.Name = "0"
cam.CameraType = "Scriptable"
repeat wait() until game.Players.LocalPlayer.Character ~= nil
wait(1)
local char = game.Players.LocalPlayer.Character:Clone(script.Parent.ViewportFrame)
char:WaitForChild("Animate"):Destroy()
char:WaitForChild("HumanoidRootPart").Anchored = true
cam.CameraSubject = char.Head
cam.CFrame = char.Head.CFrame * CFrame.Angles(0, math.rad(180), 0) * CFrame.new(0, 0, 5)

My GUI contains a ViewportFrame, a script and a camera, which is created by the script.

For some reason, the character is not going inside the frame.

Please help me!

Solution:

I just cloned different accessories including the head. Turns out that the whole avatar is not Archived; thanks, AmazingLeobreaker66!

Thank you for trying to figure this out, BlackOrange3343, but your script didn't work.

Here is my script now:

local cam = Instance.new("Camera", script.Parent)
cam.Name = "0"
cam.CameraType = "Scriptable"
script.Parent.ViewportFrame.CurrentCamera = cam
repeat wait() until game.Players.LocalPlayer.Character ~= nil
wait(1)
local head = game.Players.LocalPlayer.Character:WaitForChild("Head"):Clone()
head.Parent = script.Parent.ViewportFrame
head.Anchored = true
cam.CameraSubject = head
cam.CFrame = head.CFrame * CFrame.Angles(0, math.rad(180), 0) * CFrame.new(0, 0, 2)
for _, v in pairs(game.Players.LocalPlayer.Character:GetChildren()) do
	if v:IsA("Accessory") then
		local i = v.Handle:Clone()
		i.Parent = script.Parent.ViewportFrame
		i.Anchored = true
	end
end

Thanks for all the support!

Result:

http://i.ibb.co/wz0MDLh/Annotation-2019-10-22-134631.png

3 comments

0

You can't clone the player's character, it's not archivable.(I think)

0

hmm... ok

0

You can just set Archivable to true on all the parts.

2 answers

Solution:

I just cloned different accessories including the head. Turns out that the whole avatar is not Archived; thanks, AmazingLeobreaker66!

Thank you for trying to figure this out, BlackOrange3343, but your script didn't work.

Here is my script now:

local cam = Instance.new("Camera", script.Parent)
cam.Name = "0"
cam.CameraType = "Scriptable"
script.Parent.ViewportFrame.CurrentCamera = cam
repeat wait() until game.Players.LocalPlayer.Character ~= nil
wait(1)
local head = game.Players.LocalPlayer.Character:WaitForChild("Head"):Clone()
head.Parent = script.Parent.ViewportFrame
head.Anchored = true
cam.CameraSubject = head
cam.CFrame = head.CFrame * CFrame.Angles(0, math.rad(180), 0) * CFrame.new(0, 0, 2)
for _, v in pairs(game.Players.LocalPlayer.Character:GetChildren()) do
	if v:IsA("Accessory") then
		local i = v.Handle:Clone()
		i.Parent = script.Parent.ViewportFrame
		i.Anchored = true
	end
end

Thanks for all the support!

Try this:

--// Services
local Players = game:GetService("Players")

--// Vars
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()

local cam = Instance.new("Camera", script.Parent)
cam.Name = "0"
cam.CameraType = "Scriptable"

Character.Archivable = true

local copyChar = Character:Clone()
copyChar.Animate:Destroy()
copyChar.PrimaryPart.Anchored = true

cam.CameraSubject = copyChar.Head
cam.CFrame = copyChar.Head.CFrame * CFrame.Angles(0, math.rad(180), 0) * CFrame.new(0, 0, 5)

This will not work because it hasn't been parented to a ViewPortFrame. Remember, the model has to be in the viewport frame and the Camera has to be the ViewPortFrame's Camera.

EDIT: Sorry I forgot I had the reference on top.

3 comments

0

I'm sorry but 1: I figured it out myself and 2: your script doesn't work.

0

Horrible code. repeat wait() until game.Players.LocalPlayer.Character ~= nil? Really? You are a community moderator have 2000 reps and can't even properly yield? And what is game.Players.LocalPlayer.Character:Clone(script.Parent.ViewportFrame)? Why did you give it argument if :Clone takes none?

0

@Owengren I said it wasn't suppose to work, @programmerHere, sorry I forgot to remove the reference.

This discussion is preserved as it was. New answers, comments, and votes are closed.