Camera system not working with streaming enabled (Part Streaming)

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!

1 Like

StreamingEnabled usually breaks things because it temporarily deletes objects that are out of streaming range, so try increasing it.

Ok, I will have a go and see if it is practical. :smile:

Is there a possibility of one making their own part streamer so that those individual camera parts and their small surroundings can be avoided while still having streaming enabled?

Try what I mentioned in my post here:

1 Like

I’m 99% sure there isn’t. Streaming is basically another way of rendering objects, so it cannot be modified like that.

1 Like

Seems to work perfectly, thank you very much. :grinning:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.