local plr = game.Players.LocalPlayer local char = plr.Character local camera = workspace.CurrentCamera local Model = workspace:FindFirstChild("For thumbnail") local main = Model.MainCam local char = plr.Character repeat wait() camera.CameraType = Enum.CameraType.Scriptable until camera.CameraType == Enum.CameraType.Scriptable camera.CFrame = main.CFrame
I get error: ServerScriptService.Camera:2: attempt to index local 'plr' (a nil value)
Hello,
One way you can achieve your camera manipulation is by putting a Local Script
into StarterPlayerScripts
-- Variables local plr = game.Players.LocalPlayer -- local player local char = plr.Character -- local players's character local cam = game.Workspace.CurrentCamera local Model = game.Workspace["For thumbnail"] -- change this to wherever your model is local main = Model.CamPart -- and change this to your cam part -- Local function function CamManipulation() wait() cam.CameraType = 'Scriptable' -- cam type cam.CFrame = main.CFrame -- the place you want the cam to be at wait(5) -- add how long you want it to be like that cam.CameraType = 'Custom' -- normal cam.CameraSubject = char -- normal end -- call Function plr.CharacterAdded:Connect(CamManipulation)
I am not 100% sure what you are need from this code as you have not explain what you are doing. Please check here for details of what is useful to include in a question.
The Camera is only relivant to the client and it is not shared with anyone else. Your error ServerScriptService.Camera:2: attempt to index local 'plr' (a nil value)
is explaining that on line 2 of that script the variable named plr
holds a nil value. This is because LocalPlayer only exists on the client. A LocalScript runs on the players device meaning that LocalPlayer will always be that player and can never logicly be any other.
You are asking the server to access LocalPlayer but a server manages all players so has no idea of what a local player is.
Back to the code....
When a player joins one of the servers tasks is to replicate the game world to the player. This is not done at the same time so your local script can run before the things needed are loaded. You can use WaitForChild to yeild (make the code pause at this function) while this child name not present. When this child name is added you can safely run the code you need.
Lastly search for the event that does the task you need. Never use loops when there are events available to you. CharacterAdded should be the event you use to change the camera upon player spawn.
Example:-
local plr = game:GetService("Players") local cam = workspace.CurrentCamera -- wait for items to load into the game before you can use them local model = workspace:WaitForChild("For thumbnail"):Wait("MainCam") -- setup camera function local function setupCamera() -- you correctly used enums which is very good cam.CameraType = Enum.CameraType.Scriptable cam.CFrame = model.CFrame end -- connect event plr.CharacterAdded:Connect(setupCamera) -- adds the function setupCamera to the event call list setupCamera() -- player may have spawned before the local script can run
Hope this helps