I remade, like, all of the code and there is still a delay when switching the cameras.
-- Services --
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Lighting = game:GetService("Lighting")
local Players = game:GetService("Players")
local TweenService = game:GetService("TweenService")
-- Player Elements --
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Camera = game.Workspace.CurrentCamera
local PlayerGui = Player.PlayerGui
local Humanoid = Character:FindFirstChild("Humanoid")
local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart")
-- UI Elements --
local shopFrame = script.Parent.Frame
local shopTitle = shopFrame.Title
local exitButton = shopFrame.Exit
local loadingFrame = PlayerGui.Transition.Frame
-- Workspace Elements --
local shopDoor = game.Workspace.LobbyRoom.ShopDoor
local shopCam = game.Workspace.Shup:WaitForChild("ShopCamera")
local tp1 = game.Workspace.Shup.ShopTP1
local tp2 = game.Workspace.LobbyRoom.ShopTP2
local backgroundMusic = game.Workspace["Background Theme"]
local shopMusic = game.Workspace["Shop Theme"]
-- Lighting Elements --
local blur = Lighting.Blur
-- Tween Info --
local genInfo = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0) -- Blur + Loading
local titleInfo = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, true, 0) -- KnifeBrawl Title Sway + Cam Sway
-- Tweens --
local frameTweenOpen = TweenService:Create(loadingFrame, genInfo, {BackgroundTransparency = 0})
local frameTweenClose = TweenService:Create(loadingFrame, genInfo, {BackgroundTransparency = 1})
local blurtweenOpen = TweenService:Create(blur, genInfo, {Size = 24})
local blurtweenClose = TweenService:Create(blur, genInfo, {Size = 0})
local titleTweenRight = TweenService:Create(shopTitle, titleInfo, {Rotation = 2})
local titleTweenLeft = TweenService:Create(shopTitle, titleInfo, {Rotation = -2})
local camTiltRight
local camTiltLeft
-- Coroutines --
local titleCoroutine
local camCoroutine
-- Functions --
function openTransition(song, vol)
local musicTween = TweenService:Create(song, genInfo, {Volume = vol})
frameTweenOpen:Play()
musicTween:Play()
musicTween.Completed:Wait()
song:Stop()
end
function closeTransition(song, vol)
local musicTween = TweenService:Create(song, genInfo, {Volume = vol})
song:Play()
frameTweenClose:Play()
musicTween:Play()
musicTween.Completed:Wait()
end
local shopCamEnabled = false
local changeCam = false
function shopCamToggle()
if shopCamEnabled == false then
shopCamEnabled = true
changeCam = false
Camera.CameraType = "Scriptable"
Camera.Changed:Connect(function()
if Camera.CameraType ~= "Scriptable" and changeCam == false then
Camera.CameraType = "Scriptable"
end
end)
Camera.CFrame = shopCam.CFrame
Camera.FieldOfView = 80
camTiltRight = TweenService:Create(Camera, titleInfo, {CFrame = Camera.CFrame * CFrame.Angles(0,0,math.rad(1))})
camTiltLeft = TweenService:Create(Camera, titleInfo, {CFrame = Camera.CFrame * CFrame.Angles(0,0,math.rad(-1))})
camCoroutine = coroutine.create(function()
while true do
camTiltRight:Play()
camTiltRight.Completed:Wait()
camTiltLeft:Play()
camTiltLeft.Completed:Wait()
end
end)
coroutine.resume(camCoroutine)
else
changeCam = true
Camera.CameraType = "Custom"
Camera.FieldOfView = 100
shopCamEnabled = false
coroutine.close(camCoroutine)
end
end
local debounce = false
shopDoor.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and game.Players:GetPlayerFromCharacter(hit.Parent).UserId == Player.UserId and debounce == false then
debounce = true
print(Humanoid)
print(HumanoidRootPart)
openTransition(backgroundMusic, 0)
task.wait(0.5)
HumanoidRootPart.CFrame = tp1.CFrame
Humanoid.WalkSpeed = 0
shopCamToggle()
titleCoroutine = coroutine.create(function()
while true do
titleTweenRight:Play()
titleTweenRight.Completed:Wait()
titleTweenLeft:Play()
titleTweenLeft.Completed:Wait()
end
end)
coroutine.resume(titleCoroutine)
task.wait(0.5)
closeTransition(shopMusic, 0.5)
blurtweenOpen:Play()
blurtweenOpen.Completed:Wait()
shopFrame:TweenPosition(UDim2.new(0.5, 0 ,0.5, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Elastic, 1.5, true)
debounce = false
end
end)
local exitDebounce = false
exitButton.MouseButton1Click:Connect(function()
if exitDebounce == false then
exitDebounce = true
shopFrame:TweenPosition(UDim2.new(0.5, 0 ,1.5, 0), Enum.EasingDirection.In, Enum.EasingStyle.Sine, 1.5, true)
blurtweenClose:Play()
coroutine.close(titleCoroutine)
openTransition(shopMusic, 0)
task.wait(0.5)
HumanoidRootPart.CFrame = tp2.CFrame
Humanoid.WalkSpeed = 13
shopCamEnabled = false
shopCamToggle()
task.wait(0.8)
closeTransition(backgroundMusic, 0.5)
exitDebounce = false
end
end)
There is also a problem where the camera likes to tween between the entrance to the shop and the actual shop camera?