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

Why does my camera setting script not work consistently?

I'm trying to set the camera to a position on player spawn, and this is the code I'm currently using, but sometimes it doesn't actually set the camera to the CFrame of the cameraPart and then resets back to the player's view. Any ideas?

local camera = workspace.CurrentCamera

repeat wait ()
	camera.CameraType = Enum.CameraType.Scriptable
until camera.CameraType == Enum.CameraType.Scriptable
camera.CFrame = workspace.locationA.cameraPart.CFrame

1 answer

Although the script have several bad practices, I can see what are you trying to do, but the reason why it doesn't work is because Roblox's default script sets the CameraType back to default when the player is fully loaded and the script is trying to set the CameraType before the player is loaded. To avoid this a simple solution would be updating the camera's position to locationA and have the Scriptable CameraType forever:

local camera = workspace.CurrentCamera

while wait() do
	camera.CameraType = Enum.CameraType.Scriptable
	camera.CFrame = workspace.LocationA.cameraPart.CFrame
end

1 comment

2

wait() is a code smell. wait() can be replaced with game.RunService.Heartbeat:Wait()

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