I’m trying to script a picture of a player’s head pop up in a viewport frame.
The problem is whenever I try this, my “newCharacter” is nil in the output.
Code in a local script located in the StarterGui I used to experiment my issue
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
while true do
local newCharacter = character:Clone() -- equal to nil
newCharacter.Parent = workspace
newCharacter:MoveTo(character.PrimaryPart.Position + Vector3.new(0,10,0))
task.wait(1)
end
Code in an if statement located in a local script in the StarterGui
print(character)
print("-------")
local camera = Instance.new("Camera")
local newVPF = VPF:Clone()
local newCharacter = character:Clone()
print(newCharacter)
camera.CFrame = CFrame.lookAt(newCharacter:FindFirstChild("Head").Position + Vector3.new(0,0,2),newCharacter.Head.Position)
newCharacter.Parent = newVPF
newVPF.CurrentCamera = camera
camera.Parent = newVPF
newVPF.Parent = holder:FindFirstChild(stat).CharacterHold
for i,v in newCharacter:GetDescendants() do if v:IsA("Script") or v:IsA("LocalScript") or v:IsA("ModuleScript") then v:Destroy() end end
Code on the server I tried to fix my issue
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
for i = 1,10 do
local newCharacter = character:Clone()
newCharacter.Parent = workspace -- newCharacter in output says nil on this line
newCharacter:MoveTo(character.PrimaryPart.Position + Vector3.new(0,10,0))
end
end)
end)