Camera Target help

I’m working on a script that it’s function is that the camera looks to a block, i mean that the camera aim the block. So this is my script:

cam.CameraType = Enum.CameraType.Scriptable
local Target = game.Workspace:WaitForChild("ppartt")

cam.CFrame = CFrame.new(cam.CFrame.p,Target.Position)

I already have asked for help and saw the wiki but it didn’t help me. I hope you can help me, thanks.

I have tried this code, and it works. What issue are you having?

it doesn’t works for me, also, i forgot to type in the script box:

local cam = game.Workspace.CurrentCamera

I typed this on a localscript at starterplayerscripts, and it doesn’t prints an error

Check and make sure you dont have any other plugins or scripts interfering with the camera

I removed all the plugins right now and i started in a baseplate. And still doesn’t works

Do a debug and place a print(“Test”) after:

local Target = game.Workspace:WaitForChild(“ppartt”)

and see if it prints Test

Okay, I found a quick fix. Put a wait() before you manipulate the camera.

2 Likes

@Jaycbee05 it prints
@imalex4 i dont know if it worked or not, cause i want to the player looks the block, for example:
attachment 1 (camera) is looking at attachment 2 (block) but by any reason the camera is floating and maybe aiming the block… like dragon ball rage, pressing a button the camera target a player.

i believe the issue here is that you are placing the local script with the way you made it in the Starterplayerscripts try placing it in the Startercharcterscripts instead

honestly i don’t really understand what’s the issue, does any error appears in the output tab?

It didn’t prints something, but the issue that i got now is that the script is aiming the block but from the sky, and i want to the script aim the block form the player, like Dragon Ball Rage.

Ok, i found the issue, the problem is that you are setting the camera to Scriptable to early, i believe the Starterplayerscripts are one of the first to be Replicated into the player, so to fix your issue all you need to do is add a wait before you set it to Scriptable:

Wait(2)
cam.CameraType = Enum.CameraType.Scriptable
local Target = game.Workspace:WaitForChild("ppartt")

cam.CFrame = CFrame.new(cam.CFrame.p,Target.Position)

^ This works more efficiently

repeat cam.CameraType = Enum.CameraType.Scriptable;
until cam.CameraType == Enum.CameraType.Scriptable;

local Target = game.Workspace:WaitForChild("ppartt");

cam.CFrame = CFrame.new(cam.CFrame.p,Target.Position);

the script got fixed but i want to know why the script is aiming the block from the sky instead from the player

looks like it was aiming from the player to the block, what im meaning, that the player’s camera was at the same position as the character aiming the block, but when the player moves or the position of the block updates, stop aiming

EDIT: nevermind, it was at the sky too, just with another pos.

Since the character spawns in the sky (I assume you are just testing in Studio), the camera will also start in the sky. When the camera mode is set to Scriptable, the camera will stop following the player, even though the player is still falling.

cam.CFrame = CFrame.new(cam.CFrame.p,Target.Position);

Then, this code makes the camera look at the part, but it keeps the camera’s current position (which is in the sky).

1 Like

But how i do that the camera follows the player? thats my question

EDIT: When i don’t use while true do, the camera position will be close from the baseplate, using while true do, the camera position will be at the sky

Dont set it to scriptable , if you want the camera to still follow the player
or set it scriptible then back to custom(default)

for a following one just change the camera type, eg
camera.CameraType = Enum.Cameratype.Follow
this explains a lot, follow means it will follow the player, I recommend setting it on the humanoid rather than character.

the script prints that callbuttons is nil, doesn’t exists