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

Why does my camera setting script not work consistently?

Asked by
qfoxb 26
2 years ago

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

Log in to vote
1
Answered by
Xapelize 2658 Moderation Voter Community Moderator
2 years ago
Edited 2 years ago

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
2
wait() is a code smell. wait() can be replaced with game.RunService.Heartbeat:Wait() MarkedTomato 810 — 2y
Ad

Answer this question