Map Preview system really buggy. Need help making it not buggy

Greetings! I created this camera system,
However, it sometimes focuses on the player like this:

I need help trying to fix it.

If you can help me, please let me know!

Code:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Workspace = game:GetService("Workspace")
local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")
local Player = game:GetService("Players").LocalPlayer

local Map = Workspace:WaitForChild("Map")
local CameraParts = Map.CameraParts
local CameraInfo = TweenInfo.new(4, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, 0, false)
local ZoomOnPlayerInfo = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false)

local Camera = Workspace.CurrentCamera

ReplicatedStorage.ShowMapPreview.OnClientEvent:Connect(function(MapName, LapCount, Creator)
	Player.PlayerGui.MapMusic.PreviewMap:Play()
	script.Parent.MapName.Text = MapName
	script.Parent.LapCount.Text = "Laps: ".. LapCount
	script.Parent.Creator.Text = "Created by ".. Creator
	script.Parent.Visible = true
	Camera.CameraType = Enum.CameraType.Scriptable
	for _, CameraFolders in pairs(CameraParts:GetChildren()) do
		if CameraFolders:IsA("Folder") then
			RunService.RenderStepped:Wait()
			Camera.CFrame = CameraFolders.Begin.CFrame
			RunService.RenderStepped:Wait()
			local Tween = TweenService:Create(Camera, CameraInfo, {CFrame = CameraFolders.End.CFrame})
			Tween:Play()
			Tween.Completed:Wait()
		end	
	end
	script.Parent.Visible = false
	task.wait(2)
	Camera.CameraType = Enum.CameraType.Custom
	RunService.RenderStepped:Wait()
	local EndCFrame = Camera.CFrame
	Camera.CameraType = Enum.CameraType.Scriptable
	RunService.RenderStepped:Wait()
	Camera.CFrame = CameraParts.BeginCam.CFrame
	local Tween = TweenService:Create(Camera, ZoomOnPlayerInfo, {CFrame = EndCFrame})
	Tween:Play()
	Tween.Completed:Wait()
	Camera.CameraType = Enum.CameraType.Custom
end)

Thanks in advance!

1 Like

Due to Roblox being kinda scuffed, the default scripts set CameraType almost immediately but after custom scripts run, causing any custom script that sets CameraType to have that overwritten unless you use this workaround >.<

Basically, any LocalScript that sets CameraType immediately when the player joins should wait for the built-in scripts to set it first, otherwise it will be overwritten.

I think that might be the cause. You might be able to prevent it by overwriting CameraScript, but then you have to implement your own camera system