dragonmnl
dragonmnl

Reputation: 15558

Why is Camera position always the same in Roblox?

local RunService = game:GetService('RunService')

local function onHeartbeat()
    local cameraPos = game.Workspace.Camera.CFrame.Position -- Also tried with Workspace.currentCamera
    print(cameraPos)
end

RunService.Heartbeat:Connect(onHeartbeat)

Why is the printed value always the same even if the player (and therefore also the camera?) moves?

Upvotes: 1

Views: 228

Answers (1)

Kylaaa
Kylaaa

Reputation: 7188

Testing in Roblox Studio often makes it a little difficult to distinguish between the view from the client and server. When your character is running around, and the camera is following your player, you are seeing the view from your client.

The server also has access to the workspace camera, but with nothing to drive it around, it remains stationary. You can see this when you play by going to the Test tab, and clicking on the Current : Client button to toggle over to the server view.

enter image description here

Your Script runs on the server, so it is always checking the server's version of the camera, which is stationary. However, if you were to move this code into a LocalScript in StarterPlayerScripts, you'd see that the position of the player's workspace camera updates the way you would expect.

Upvotes: 2

Related Questions