Hello, I find it extremely hard to work with viewports (suprisingly harder than datastores) and I’ve ran into a issue where I wish to show a player’s character (who is in a leaderboard) in a viewport, I got everything sorted apart from the viewports
This is what I have been experimenting with right now:
game.Players:CreateHumanoidModelFromUserId(113260028).Parent = script.Parent
local model = script.Parent:WaitForChild("Player")
model.Name = " "
local camera = Instance.new("Camera")
script.Parent.CurrentCamera = camera
camera.Parent = script.Parent
camera.CFrame = model.PrimaryPart.Position
I hate working with viewports myself, I can never seem to get it within the first few tries. Once the issue I had was the position was at a random place. Try to set
The line you provided is currently erroring, here is the modified code
game.Players:CreateHumanoidModelFromUserId(113260028).Parent = script.Parent.ViewportFrame
local model = script.Parent.ViewportFrame:WaitForChild("Player")
model.Name = " "
model.PrimaryPart.Position = Vector3.new(0, 0, 0)
local camera = Instance.new("Camera")
script.Parent.ViewportFrame.CurrentCamera = camera
camera.Parent = script.Parent.ViewportFrame
camera.CFrame = model.PrimaryPart.Position
Errors:
23:52:07.697 Workspace.Face.SurfaceGui.Script:10: invalid argument #3 (CFrame expected, got Vector3) - Server - Script:10
23:52:07.697 Stack Begin - Studio
23:52:07.697 Script 'Workspace.Face.SurfaceGui.Script', Line 10 - Studio - Script:10
23:52:07.697 Stack End - Studio
23:52:07.697 0 - Server - Script:13
23:52:07.764 Workspace.Face.SurfaceGui.ViewportFrame.Script:4: invalid argument #3 (Vector3 expected, got CFrame) - Server - Script:4
23:52:07.764 Stack Begin - Studio
23:52:07.764 Script 'Workspace.Face.SurfaceGui.ViewportFrame.Script', Line 4 - Studio - Script:4
23:52:07.764 Stack End - Studio
Here is a tree of the objects just incase this helps:
game.Players:CreateHumanoidModelFromUserId(113260028).Parent = script.Parent.ViewportFrame
local model = script.Parent.ViewportFrame:WaitForChild("Player")
for _, v in pairs(model:GetDescendants()) do
if v:IsA("Part") then
v.Anchored = true
end
end
model.Name = " "
model.PrimaryPart.Position = Vector3.new(0, 0, 0)
local camera = Instance.new("Camera")
script.Parent.ViewportFrame.CurrentCamera = camera
camera.Parent = script.Parent.ViewportFrame
camera.CFrame = model.PrimaryPart.CFrame
local mcf = model.PrimaryPart.CFrame -- character's cframe
local center = mcf.Position + mcf.LookVector*10 -- 10 studs from the character
local lookingAt = mcf.Position
camera.CFrame = CFrame.lookAt(center, lookingAt)
^^ This will tell the camera to position 10 studs in front of the primary part, and look at the primaryPart. If you want it to look at the head or the arm or whatever, just change lookingAt to the head’s position or the arm’s position or whatever.
[Note] CFrame.lookAt is the same as CFrame.new except lookAt takes a 3rd arguement which is the UpVector. UpVector is (0,1,0) by default. You could change this and make the Camera tilt. It’s pretty neat.
This might be the issue, the way you spawing you player model makes it all scattered around in the Frame so you didn’t see it but on the actual gui you can see some of the items.
That’s strangle, the method that was used in the script is the one that doesn’t break, why has it suddenly just screwed itself up again
Context: Load Character by UserId - #13 by Niestrat99
Update: This is really strange, it works completely fine in the command bar using game.Players:CreateHumanoidModelFromUserId(113260028).Parent = game.Workspace
So there’s this thing called a client-server model. And how that translates into Roblox experiences is that "LocalScript"s only run on client machines and "Script"s only run on the server. I got the impression that what you are doing is entirely client-based, but when I opened your model it was in a Script.
StarterPlayer.StarterPlayerScripts – used for LocalScript (s)
StarterGui – used for both LocalScript (s), ScreenGui (s), BillboardGui (s) if you want to, SurfaceGui (s) if you want to.
Now. You can place ViewportFrame (s) inside of ScreenGui (s), BillboardGui (s), and SurfaceGui (s). (I think you can at least.)
So my suggestion is to create a ScreenGui inside of StarterGui and then place a ViewportFrame inside of the ScreenGui. Place a LocalScript inside of the ViewportFrame and then edit the viewport using code.
I don’t want it to be on the screen, what my goal is to make a small leaderboard that the top player is shown in a Viewport that slowly rotates
I understand the client-server networking model but, I don’t understand why the server cannot handle viewports