I am trying to make a part that teleports your camera to another part, for a cutscene. However, it can’t find the CFrame part due to an infinite yield. I can’t find out how to fix this. Help, please!
local Local = game.Players.LocalPlayer
game:GetService("ReplicatedStorage"):WaitForChild("water").OnClientEvent:Connect(function()
Local.PlayerGui.Objectives.Enabled = false
game.Workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
game.Workspace.CurrentCamera.Focus = game.Workspace:WaitForChild("waterfocus")
game.Workspace.CurrentCamera.CFrame = CFrame.new(game.Workspace:WaitForChild("watercframe").CFrame)
end)
WaitForChild will yield the current thread (script) if the part ends up not being created. You can mitigate this by first, ensuring the part is actually created and make sure you’re waiting on the correct part.
The second way to mitigate this is to add a timeout to your WaitForChild
like so:
parent:WaitForChild("ChildPart", 10)
This will automatically timeout after 10 seconds and prevent the yielding from happening, however this will also stop waiting for the child to be instantiated.
Sorry, but I am trying to make it so the part actually does load in. If I don’t check for the part the cutscene won’t work. How do I make sure it loads in? I don’t know why it won’t check because the part does exist in the workspace.
Nevermind, I fixed it. Anyone who comes here looking for an answer, I figured it out because I was using a localscript, and had StreamingEnabled on, so it didn’t load every part at once, making it so it never had it loaded. Go into workspace and disable InstanceStreaming / StreamingEnabled to fix your problem. Hope this helps!
Do NOT disabled StreamingEnabled, this will cause immense lag in your game. You need to make sure the part is close to the camera in order for it to be rendered/instantiated. DO NOT DISABLE STREAMING ENABLED, IT IS THERE FOR A REASON