Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 7 years ago
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

0
Is this a script or a local script? MrLonely1221 701 — 7y
0
This is a script PullAnAllNighter 8 — 7y
0
Okay. Hang on MrLonely1221 701 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

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.

Ad

Answer this question