I'm making an FNaF game on Roblox and I put two Camera Blocks and I also put a GUI button to switch Cameras but It says "Attempt To Call A Nil Value"
Here's the code:
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Camera = workspace.CurrentCamera
local TurnButton = game.StarterGui.TurnGUI.TurnButton
function onClick()
repeat wait()
Camera.CameraType = Enum.CameraType.Scriptable
until Camera.CameraType == Enum.CameraType.Scriptable
Camera.CFrame = workspace.CameraPOV2.CFrame
end
script.Parent.MouseButton1Click:connect()
Can someone please help me?

4 comments
Is it a localscript?
Yes it is
I put it in the guibutton
The way to access a gui should be though script.Parent then blah blah or player:WaitForChild("PlayerGui") then your info, StarerGui is where the base guis are but the guis a player sees is replicated into a folder in the player called PlayerGui