So basically I want to clone the player's character upon joining the game and have it appear on the ViewportFrame. Currently I'm getting no errors and I simply think it's because I made a mistake while trying to clone the player's character. Any help would be appreciated as always, thanks!
--Local Script local player = game.Players.LocalPlayer local character = game.Players.LocalPlayer.Character local viewportFrame = script.Parent if player.CharacterAdded and player:FindFirstChild("Humanoid") then character.Archivable = true local clone = player.Character:Clone() clone.Position = Vector3.new(0,0,0) clone.Parent = viewportFrame local viewportCamera = Instance.new("Camera") viewportFrame.CurrentCamera = viewportCamera viewportCamera.Parent = viewportFrame viewportCamera.CFrame = CFrame.new(Vector3.new(0,2,12),clone.position) end
Alright, so there's multiple problems with your script...
Your conditional statement (if-then) is a bit incorrect. I don't think a CharacterAdded event would be a good idea to use in the statement, and you're searching for the humanoid in the player itself. The humanoid is in the character, not the player.
Then an error occurs. On line 9, clone
is a model (player characters are models), and it doesn't have a position property. Instead, you should use the :MoveTo()
function. It's pretty much the position property in the form of a function for models.
After that, another error occurs at line 16, and it's similar to the last error. clone
doesn't have a position property, but :MoveTo()
doesn't let you read the position, only change it. There's several ways to get the position, but I'm just going to get the HumanoidRootPart's position in the character.
Your script should look like this:
--Local Script local player = game.Players.LocalPlayer local character = game.Players.LocalPlayer.Character local viewportFrame = script.Parent repeat wait(1) until character ~= nil -- Waits for character to load if character:FindFirstChild("Humanoid") then character.Archivable = true local clone = player.Character:Clone() clone:MoveTo(Vector3.new(0, 0, 0)) clone.Parent = viewportFrame local viewportCamera = Instance.new("Camera") viewportFrame.CurrentCamera = viewportCamera viewportCamera.Parent = viewportFrame viewportCamera.CFrame = CFrame.new(Vector3.new(0,2,12),clone.HumanoidRootPart.Position) end
Hope this helped! If you have any questions, just comment!