When setting camera to scriptable, indefinitely crashes game

when the editor opens, i have it so the camera gets set as an overhead camera, this is for build mode in my game, and then the character just indefinitely, ever few seconds respawns and the game reloads. thank so much for any help :heart_on_fire: the only thing i can think of is that i have a custom StarterCharacter for the game but i don’t know why that would break this camera script

local gui = script.Parent
local player = game.Players.LocalPlayer
local lot = game.Workspace:WaitForChild("Lots"):WaitForChild(player.Name) -- this just gets the player's lot, so the camera can view the correct area

gui:GetPropertyChangedSignal("Visible"):Connect(function()
	if gui.Visible == true then -- edit
		local FOV = 60
		local camera = game.Workspace.CurrentCamera
		camera.FieldOfView = FOV
		camera.CameraType = Enum.CameraType.Scriptable
		local pos = lot.OverheadCam.Position -- part about 10 studs above floor, these parts are both anchored so that can't be the problem
		local pos2 = lot.LookAtPoint.Position -- part on floor for camera to be facing
		camera.CoordinateFrame = CFrame.new(pos, pos2) -- set cam
		
	else -- done, sets camera back to default when build gui is closed
		local FOV = 70
		local camera = game.Workspace.CurrentCamera
		camera.FieldOfView = FOV
		camera.CameraType = Enum.CameraType.Follow
	end
end)

maybe add a new temporary camera.

local gui = script.Parent
local player = game.Players.LocalPlayer
local lot = workspace:WaitForChild("Lots"):WaitForChild(player.Name) -- this just gets the player's lot, so the camera can view the correct area
local defaultCamera = workspace.CurrentCamera

gui:GetPropertyChangedSignal("Visible"):Connect(function()
	if gui.Visible then -- edit
		local FOV = 60
		local camera = Instance.new("Camera")
		camera.FieldOfView = FOV
		camera.CameraType = Enum.CameraType.Scriptable
		local pos = lot.OverheadCam.Position -- part about 10 studs above floor, these parts are both anchored so that can't be the problem
		local pos2 = lot.LookAtPoint.Position -- part on floor for camera to be facing
		camera.CFrame = CFrame.new(pos, pos2) -- set cam
        workspace.CurrentCamera = camera
	else -- done, sets camera back to default when build gui is closed
		workspace.CurrentCamera = defaultCamera
	end
end)
2 Likes

or in the script you make the GUI visible, you can just change camera there to prevent loops

1 Like

nope it didn’t work, i parented the camera to workspace and put workspace.CurrentCamera = camera , is that what im supposed to do?

try CFrame.lookAt()

local gui = script.Parent
local player = game.Players.LocalPlayer
local lot = game.Workspace:WaitForChild("Lots"):WaitForChild(player.Name) -- this just gets the player's lot, so the camera can view the correct area

gui:GetPropertyChangedSignal("Visible"):Connect(function()
	if gui.Visible then -- edit
		local FOV = 60
		local camera = workspace.CurrentCamera
		camera.FieldOfView = FOV
		camera.CameraType = Enum.CameraType.Scriptable
		local pos = lot.OverheadCam.Position -- part about 10 studs above floor, these parts are both anchored so that can't be the problem
		local pos2 = lot.LookAtPoint.Position -- part on floor for camera to be facing
		camera.CFrame = CFrame.lookAt(pos, pos2) -- set cam
	else -- done, sets camera back to default when build gui is closed
		local FOV = 70
		local camera = workspace.CurrentCamera
		camera.FieldOfView = FOV
		camera.CameraType = Enum.CameraType.Custom
        camera.CameraSubject = player.Character.Head
	end
end)
1 Like

yes, I just forgot to do that (sorry)

1 Like

sadly nope, still crashes. i honestly think this could be some kind of internal bug with roblox’s camera system or something. im gonna send a bug report

1 Like
local gui = script.Parent
local player = game.Players.LocalPlayer
local lot = game.Workspace:WaitForChild("Lots"):WaitForChild(player.Name) -- this just gets the player's lot, so the camera can view the correct area

gui:GetPropertyChangedSignal("Visible"):Connect(function()
	if gui.Visible == true then -- edit
		local FOV = 60
		local camera = game.Workspace.Camera
		camera.FieldOfView = FOV
		camera.CameraType = Enum.CameraType.Scriptable
		local pos = lot.OverheadCam.Position -- part about 10 studs above floor, these parts are both anchored so that can't be the problem
		local pos2 = lot.LookAtPoint.Position -- part on floor for camera to be facing
		camera.CFrame = CFrame.new(pos, pos2) -- set cam
		
	else -- done, sets camera back to default when build gui is closed
		local FOV = 70
		local camera = game.Workspace.Camera
		camera.FieldOfView = FOV
		camera.CameraType = Enum.CameraType.Follow
	end
end)
1 Like

that’s literally the same thing as the provided script

1 Like

ita kindaa differenttt

(character limit)

1 Like

OP’s script:

local gui = script.Parent
local player = game.Players.LocalPlayer
local lot = game.Workspace:WaitForChild("Lots"):WaitForChild(player.Name) -- this just gets the player's lot, so the camera can view the correct area

gui:GetPropertyChangedSignal("Visible"):Connect(function()
	if gui.Visible == true then -- edit
		local FOV = 60
		local camera = game.Workspace.CurrentCamera
		camera.FieldOfView = FOV
		camera.CameraType = Enum.CameraType.Scriptable
		local pos = lot.OverheadCam.Position -- part about 10 studs above floor, these parts are both anchored so that can't be the problem
		local pos2 = lot.LookAtPoint.Position -- part on floor for camera to be facing
		camera.CoordinateFrame = CFrame.new(pos, pos2) -- set cam
		
	else -- done, sets camera back to default when build gui is closed
		local FOV = 70
		local camera = game.Workspace.CurrentCamera
		camera.FieldOfView = FOV
		camera.CameraType = Enum.CameraType.Follow
	end
end)

your script:

local gui = script.Parent
local player = game.Players.LocalPlayer
local lot = game.Workspace:WaitForChild("Lots"):WaitForChild(player.Name) -- this just gets the player's lot, so the camera can view the correct area

gui:GetPropertyChangedSignal("Visible"):Connect(function()
	if gui.Visible == true then -- edit
		local FOV = 60
		local camera = game.Workspace.Camera
		camera.FieldOfView = FOV
		camera.CameraType = Enum.CameraType.Scriptable
		local pos = lot.OverheadCam.Position -- part about 10 studs above floor, these parts are both anchored so that can't be the problem
		local pos2 = lot.LookAtPoint.Position -- part on floor for camera to be facing
		camera.CFrame = CFrame.new(pos, pos2) -- set cam
		
	else -- done, sets camera back to default when build gui is closed
		local FOV = 70
		local camera = game.Workspace.Camera
		camera.FieldOfView = FOV
		camera.CameraType = Enum.CameraType.Follow
	end
end) 

the only difference is Camera and CurrentCamera
and CurrentCamera is better

guys nevermind sorry about this, turns out the parts were just too close together. thanks so much for all your help

2 Likes

oh ok :+1:

(character limit thingy)