I’ve tried looking it up and there have been almost no results, I’m trying to get the cameras position, and then display it onto a text label in a GUI, I’ve looked through a few posts and none of them worked, any help would be appreciated.
You can use:
local cameraPos = workspace.CurrentCamera.CFrame.Position
If you want the whole CFrame, stop with just the CFrame, if you want position or rotation, just add “.Position” or “.Orientation” onto the end.
So it would be like this?
local cameraPos = workspace.CurrentCamera.CFrame.Position
while true do
wait()
script.Parent.Text = "POSITION: (" ..cameraPos ")"
end
If it is, then it gives me the error “attempt to call a Vector3 value”
The returned position is a Vector3 value, you have to break it up into pieces, like this:
script.Parent.Text = "POSITION: (" ..tostring(cameraPos.X)..","..tostring(cameraPos.Y)..","..tostring(cameraPos.Z)..")"
Didn’t give me an error, but it didn’t show anything in the text label. Am I doing something wrong here?
local cameraPos = workspace.CurrentCamera
while task.wait() do
script.Parent.Text = POSITION: (" ..cameraPos.CFrame ")"
end
this might work, sorry if it doesnt, i was typing with my phone
The POSITION: isn’t a variable, it’s supposed to be POSITION: camera position. )
oh, i didn’t read the script correctly
script.Parent.Text = "Position: (" ..cameraPos.CFrame ")"
The cameraPos variable is already a CFrame of the Camera. But it still doesn’t work.
Pr0pelled’s code works for me
local cameraPos = workspace.CurrentCamera.CFrame
while task.wait() do
script.Parent.Text = "POSITION: (" ..tostring(cameraPos.X)..","..tostring(cameraPos.Y)..","..tostring(cameraPos.Z)..")"
end
For some reason, it doesn’t for me. Unless I’m supposed to put it in something other than a local script, which I don’t think that’d make much sense.
maybe try this?
local camera= workspace.CurrentCamera
while task.wait() do
script.Parent.Text = "Position: (" ..tostring(camera.CFrame.Position) ")"
end
i thought the issue might be that because you were doing workspace.CurrentCamera.CFrame it wasn’t being updated every second
Nope. Doesn’t even update the text this time.
try running this
local camera= workspace.CurrentCamera
while true do
wait()
print(camera.CFrame.Position)
end
i gotta go now but lmk what it prints
It’s printing the camera position, but for some reason it just doesn’t appear on the text box.
CFrame is short for “Coordinate frame”, which would return the Position & Orientation. If you’d like to incorporate it into a string, try this:
local Position = workspace.CurrentCamera.CFrame.Position
while true do
task.wait()
script.Parent.Text = "POSITION: ("..string.format("%.14g", Position)..")"
end
Same thing, still doesn’t update the text.
script.Parent.Text = "Position: ("..tostring(camera.CFrame.Position)..")"
just realized the format was wrong, this should work. I really have to go now though.
This worked, but is there any way to make it… simpler? or less bulky? Like, as in a vector3 value.
local Position = workspace.CurrentCamera.CFrame.Position
while true do
task.wait()
script.Parent.Text = tostring("POSITION: ("..tonumber(string.format("%.14g", math.floor(Position)))..")")
end