So I’m just trying viewport frames out and I wanted to clone the players character to the viewport frame but it keeps on saying attempt to index nil with 'Parent'.
Heres the code
local ch = workspace:WaitForChild('5C_B')
if ch ~= nil then
ch:Clone().Parent = script.Parent.ViewportFrame
end
local playerToClone = "5C_B"
function CloneMe(char) --a function that clones a player
char.Archivable = true
local clone = char:Clone()
char.Archivable = false
return clone
end
local charClone = CloneMe(game.Players[playerToClone].Character) --connects function and defines "charClone" as the result of the function
charClone.Parent = script.Parent.ViewportFrame
local ch = workspace:WaitForChild('5C_B')
local waiting = workspace:FindFirstChild(ch)
if not waiting then
ch:Clone().Parent = script.Parent.ViewportFrame
end
if “waiting” doesn’t work replace it with workspace:FindFirstChild(“5C_B”)
What player’s character are you trying to clone into the ViewportFrame? Is it the local player? Also, instead of doing workspace:WaitForChild() with the player’s name, try getting the player object and checking if Player.Character is there before attempting to clone it. Here’s some example code for a LocalScript assuming you’d want to clone the local player:
local ViewportFrame = script.Parent.ViewportFrame
local function PutCharacterIntoViewport(Player,VPF)
if Player.Character then
Player.Character:Clone().Parent = VPF
end
end
PutCharacterIntoViewport(game:GetService("Players").LocalPlayer,ViewportFrame)