I am trying to make a intro menu camera scene with three different sections. It currently works without streaming enabled and does not with streaming enabled. I presume this is because the parts the camera is supposed to travel to are not loaded as they are distant from the player.
I don’t really know what i’m doing when it comes to the streaming enabled property as i have not really used it much before so please leave a descriptive suggestion of how this problem could be resolved.
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local LocalPlayer = Players.LocalPlayer
local CurrentCamera = workspace.CurrentCamera
local Part1 = workspace:WaitForChild("MenuCam")
local Part2 = workspace:WaitForChild("Scene2Cam")
local Part3 = workspace:WaitForChild("Scene3Cam")
local PlayBTN = script.Parent["Team Switcher"].Neutral
CurrentCamera.CameraType = Enum.CameraType.Scriptable
CurrentCamera.CFrame = Part1.CFrame
local duration = 5
local startTime
local scene = 1
local animating = true
local function lerp(a, b, t)
return a + (b - a) * t
end
local function animateCamera(deltaTime)
if not startTime then
startTime = tick()
end
local elapsedTime = tick() - startTime
local alpha = math.clamp(elapsedTime / duration, 0, 1)
if scene == 1 then
local startPos = Part1.Position
local endPos = startPos + Vector3.new(0, 0, 40)
local newPos = lerp(startPos, endPos, alpha)
CurrentCamera.CFrame = CFrame.new(newPos, startPos)
if alpha >= 1 then
scene = 2
startTime = tick()
end
elseif scene == 2 then
local startPos = Part2.Position
local endPos = startPos + Vector3.new(0, 0, -50)
local newPos = lerp(startPos, endPos, alpha)
CurrentCamera.CFrame = CFrame.new(newPos, startPos)
if alpha >= 1 then
scene = 3
startTime = tick()
end
elseif scene == 3 then
local startCFrame = Part3.CFrame
local endCFrame = startCFrame * CFrame.Angles(math.rad(-45), 0, 0)
CurrentCamera.CFrame = startCFrame:Lerp(endCFrame, alpha)
if alpha >= 1 then
animating = false
end
end
end
RunService.RenderStepped:Connect(function(deltaTime)
if animating then
animateCamera(deltaTime)
end
end)
LocalPlayer.CharacterAdded:Connect(function(character)
CurrentCamera.CameraType = Enum.CameraType.Custom
animating = false
end)
function Play()
CurrentCamera.CameraType = Enum.CameraType.Custom
script.Parent:Destroy()
end
PlayBTN.MouseButton1Click:Connect(Play)
Cheers!