Try waiting for the character before cloning it.
Like this:
local Character = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
local clone = Character:Clone()
-- Rest of the code
Try waiting for the character before cloning it.
Like this:
local Character = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
local clone = Character:Clone()
-- Rest of the code
Changed the code, it still shows the same error.
Maybe that’s because the clone fell of the word. Try setting the HumanoidRootPart of the clone to a position that he isn’t going to die.
local viewportFrame = Instance.new("ViewportFrame")
viewportFrame.Size = UDim2.new(0.3, 0, 0.4, 0)
viewportFrame.Position = UDim2.new(0, 15, 0, 15)
viewportFrame.BackgroundColor3 = Color3.new(0.196078, 0.196078, 0.196078)
viewportFrame.BorderSizePixel = 0
viewportFrame.Parent = script.Parent
local Character = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
local clone = Character:Clone()
clone.HumanoidRootPart.Position = Vector3.new(-80.67, 0.5, -244.88)
clone.Parent = viewportFrame
local viewportCamera = Instance.new("Camera")
viewportFrame.CurrentCamera = viewportCamera
viewportCamera.Parent = viewportFrame
viewportCamera.CFrame = CFrame.new(Vector3.new(0, 0, 10), clone.HumanoidRootPart.Position)
Same error.
I’ll try your code in my game, just a moment…
Ok, so I did some tests, and for some reason you can’t clone the player character.
I tried do clone other models and it works perfectly fine, but if I try to clone the player character it gives me an error.
I found this post, and this may help you: Can’t clone character?
But, when I set the property Archivable to true it just clones the Character model, not the descendants of the model.
So, at this point, I don’t know what to do.
Instead i can use a dummy then.
Yes, I think you could try it!
This is a great idea.
I tried using a dummy yesterday, but i had some problems with the camera angle, and that’s happening again.
local viewportFrame = Instance.new("ViewportFrame")
viewportFrame.Size = UDim2.new(0.3, 0, 0.4, 0)
viewportFrame.Position = UDim2.new(0, 15, 0, 15)
viewportFrame.BackgroundColor3 = Color3.new(0.196078, 0.196078, 0.196078)
viewportFrame.BorderSizePixel = 0
viewportFrame.Parent = script.Parent
local Character = game.ReplicatedStorage.Dummy
local clone = Character:Clone()
clone.Parent = viewportFrame
local viewportCamera = Instance.new("Camera")
viewportFrame.CurrentCamera = viewportCamera
viewportCamera.Parent = viewportFrame
viewportCamera.CFrame = CFrame.new(Vector3.new(0, 0, 10), clone.HumanoidRootPart.Position)
It did in fact work but this is the result:
Use this?
clone.Position = Vector3.new(0, 0, 10)
I’ll try that, but wouldn’t that go wrong because it’s a model and it doesn’t have a Position
property
So, this?
clone:SetPrimaryCFrame(Vector3.new(0, 0, 10))
To fix that, I just moved the dummy to the spawn.
The reason you have the problem is that a player’s character cannot be cloned because the Archivable property is set to false on default. To clone it, you need to set the archivable property to true:
local viewportFrame = Instance.new("ViewportFrame")
viewportFrame.Size = UDim2.new(0.3, 0, 0.4, 0)
viewportFrame.Position = UDim2.new(0, 15, 0, 15)
viewportFrame.BackgroundColor3 = Color3.new(0.196078, 0.196078, 0.196078)
viewportFrame.BorderSizePixel = 0
viewportFrame.Parent = script.Parent
local char = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
char.Archivable = true
local clone = char:Clone()
char.Archivable = false
clone.Parent = viewportFrame
local viewportCamera = Instance.new("Camera")
viewportFrame.CurrentCamera = viewportCamera
viewportCamera.Parent = viewportFrame
viewportCamera.CFrame = CFrame.new(Vector3.new(20, 20, 20), clone.HumanoidRootPart.Position)
I already did this, but it just clones the character model, not the descendants.
Well that looks like it works… kinda.
And if you want you can rotate it to, so it looks to the camera.
Maybe this?
local viewportFrame = Instance.new("ViewportFrame")
viewportFrame.Size = UDim2.new(0.3, 0, 0.4, 0)
viewportFrame.Position = UDim2.new(0, 15, 0, 15)
viewportFrame.BackgroundColor3 = Color3.new(0.196078, 0.196078, 0.196078)
viewportFrame.BorderSizePixel = 0
viewportFrame.Parent = script.Parent
local char = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
char.Archivable = true
for _, object in pairs(char:GetDescendants()) do
object.Archivable = true
end
local clone = char:Clone()
for _, object in pairs(char:GetDescendants()) do
object.Archivable = false
end
char.Archivable = false
clone.Parent = viewportFrame
local viewportCamera = Instance.new("Camera")
viewportFrame.CurrentCamera = viewportCamera
viewportCamera.Parent = viewportFrame
viewportCamera.CFrame = CFrame.new(Vector3.new(20, 20, 20), clone.HumanoidRootPart.Position)
I think this is happening because you set the camera CFrame to 0,0,0.
If you want you can set it to the Dummy HumanoidRootPart position + Vector.new(0,0,10)
Try this maybe:
local model = someModelHere
local size = model:GetExtentsSize()
local longest = math.max(size.x,size.y,size.z)
local distance = longest*2
camera.CFrame = CFrame.lookAt(model.PrimaryPart.Position+model.PrimaryPart.CFrame.LookVector*distance,model.PrimaryPart.Position)