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
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.