Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does this camera manipulation script work in studio but not play?

local pcam = game.Workspace.CurrentCamera
game.Players.PlayerAdded:connect(function(p)
	wait(2)
	pcam.CameraSubject = game.Workspace.CameraFocus
	wait()
	pcam.CameraType = Enum.CameraType.Scriptable
	pcam.CFrame = game.Workspace.CameraFocus.CFrame
	print("done")	
end)

Its supposed to edit the players camera on entrance to the game but it wont do anything for that player

3 comments

0

Is this a script or a local script?

0

This is a script

0

Okay. Hang on

1 answer

✓ Accepted answer

There are a couple of things here:

  1. Your script needs to be a LocalScript in order to access CurrentCamera
  2. In order for the LocalScript to run it needs to be in one of these places
  3. You can either :Clone() the script into the Player's PlayerGui or put the script in game > StarterPlayer > StarterPlayerScripts

Cloning method:

Script:

game.Players.PlayerAdded:connect(function(player)
    local camScript = script.LocalScript:Clone();
    camScript.Parent = player.PlayerGui;
    camScript.Disabled = false;
end);

LocalScript (A child of the Script, this is disabled):

local pcam = game.Workspace.CurrentCamera

pcam.CameraSubject = game.Workspace.CameraFocus;
wait();
pcam.CameraType = Enum.CameraType.Scriptable;
pcam.CFrame = game.Workspace.CameraFocus.CFrame;
print("done");

The other method is much simpler for this camera script. You would simply put the script into StarterPlayerScripts inside of StarterPlayer

I hope this helped! If it did please accept this as the answer so people know it has been solved and you have been helped. If you have any questions feel free to ask. If you have any other non-related questions feel free to ask those too.

This discussion is preserved as it was. New answers, comments, and votes are closed.