I’m trying to show a troop in the viewport frame, so the player can see what troop they are placing, however it is not rendering. Any ideas?
Result:
Code:
local troopSlot = troopBar:WaitForChild("Slot"..tostring(i))
local viewportFrame = troopSlot:WaitForChild("ViewportFrame")
local camera = viewportFrame:WaitForChild("ViewportCamera")
local troop = newTroopValue.Value:Clone()
troop.Parent = viewportFrame
camera.CameraSubject = troop
camera.CFrame = CFrame.new(troop.PrimaryPart.Position+Vector3.new(0,0,10),troop.PrimaryPart.Position)
There are no errors in the output. If you have any questions, please ask me. Thank you for the help!
1 Like
A Camera inside of a ViewportFrame is deleted for the player but stays on the server.
As you can see, I have this setup:
When I press play, the camera is gone.
When I switch to server view, it’s there.
Camera’s don’t replicate across Roblox’s server/client boundary.
What you need to do is create a camera on the client using Instance.new()
and then set the CurrentCamera of the Viewportframe to that Camera. You do not need to set the Parent of the Camera.
local troopSlot = troopBar:WaitForChild("Slot"..tostring(i))
local viewportFrame = troopSlot:WaitForChild("ViewportFrame")
local camera = Instance.new("Camera")
viewportFrame.CurrentCamera = camera
local troop = newTroopValue.Value:Clone()
troop.Parent = viewportFrame
camera.CameraSubject = troop
camera.CFrame = CFrame.new(troop.PrimaryPart.Position+Vector3.new(0,0,10),troop.PrimaryPart.Position)
Hope that helps. If you have any questions, don’t hesitate to ask me.
1 Like