so I'm putting the character clone into a viewport frame and this is a snippet of my code, is there anything wrong? I'll put the code right here

game:GetService("RunService").RenderStepped:Connect(function()
	local cc = char:Clone()
	if cc then
		if not charinviewport then
			cc.Parent = script.Parent.ViewportFrame
		end
	else
		print("no character which is impossible")
	end
	if script.Parent:FindFirstChild("Camera") and script.Parent.ViewportFrame:FindFirstChild(char.Name) then
		cam.CFrame = Part.CFrame
		
		script.Parent.ViewportFrame.CurrentCamera = cam
		script.Parent.ViewportFrame[char.Name]:Destroy()
		workspace[player.Name]:Clone().Parent = script.Parent.ViewportFrame
	end
end)

yet it prints "no character which is impossible"

here's the whole script

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local root = char:WaitForChild("HumanoidRootPart")
local charinviewport = false

local Part = Instance.new("Part")
Part.Parent = workspace
Part.CastShadow = false
Part.Massless = true
Part.Name = player.Name.."Cam"
Part.FrontSurface = Enum.SurfaceType.Hinge
local offset = Vector3.new(0,0,-8) -- in your case, Vector3.new(0,0,5), or something like that
Part.CFrame = root.CFrame*CFrame.new(offset) * CFrame.Angles(0,math.rad(180),0) -- should offset while keeping rotations of root.CFrame
local weld = Instance.new("WeldConstraint",Part)
weld.Part0 = Part
weld.Part1 = root
local cam = Instance.new("Camera")
cam.Parent = script.Parent

game:GetService("RunService").RenderStepped:Connect(function()
	local cc = char:Clone()
	if cc then
		if not charinviewport then
			cc.Parent = script.Parent.ViewportFrame
		end
	else
		print("no character which is impossible")
	end
	if script.Parent:FindFirstChild("Camera") and script.Parent.ViewportFrame:FindFirstChild(char.Name) then
		cam.CFrame = Part.CFrame
		
		script.Parent.ViewportFrame.CurrentCamera = cam
		script.Parent.ViewportFrame[char.Name]:Destroy()
		workspace[player.Name]:Clone().Parent = script.Parent.ViewportFrame
	end
end)

1 comment

0

try printing (cc.Name) to make sure it's really there as a start