Camera script not working

So i have this camera script that will make change Player Camera CFrame to the selected object. In studio they works properly but when tried in Roblox itself its not working and just yield me an error "Infinite yield possible on "workspace:WaitForChild(“MenuFocus”). And yes the object exist there

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local camera = workspace.CurrentCamera
local mainMenuCam = game.Workspace.GameMap:WaitForChild("CameraValue")
local TS = game:GetService("TweenService")
local playergui = player.PlayerGui

coroutine.wrap(function()
	while task.wait(35) do
		local Tween = TS:Create(playergui.MainGui.MainMenuFrame,TweenInfo.new(2.5),{BackgroundTransparency = 0})
		local Tween2 = TS:Create(playergui.MainGui.MainMenuFrame,TweenInfo.new(2.5),{BackgroundTransparency = 1})
		Tween:Play()
		Tween.Completed:Wait()
		task.wait(.5)
		if mainMenuCam.Value == "MenuFocus" then
			mainMenuCam.Value = "MenuFocus2"
		elseif mainMenuCam.Value == "MenuFocus2" then
			mainMenuCam.Value = "MenuFocus3"
		elseif mainMenuCam.Value == "MenuFocus3" then
			mainMenuCam.Value = "MenuFocus"
		end
		task.wait(.5)
		Tween2:Play()
	end
end)()

task.wait(5)

while task.wait() do
	print(mainMenuCam.Value)
	local menupart = workspace:WaitForChild(mainMenuCam.Value)
	camera.CameraType = Enum.CameraType.Scriptable
	camera.CFrame = menupart.CFrame
end

Could you maybe have renamed the MenuFocus to something else accidentally or forgot to publish? You likely got the infinite yield warning in game because it took you longer to load in game and it was enough time to decide to warn you

Your code seems to look fine otherwise, especially since you said it worked in studio?

Try adding a timeout value
So instead of WaitForChild('MenuFocus')
Do WaitForChild('MenuFocus', 60)

That way it won’t warn you after like 10 seconds, instead it wil warn you after 60 seconds. You change it to any value you want though it doesn’t have to be 60.

I found what’s the real issue was. It was because of streaming enabled i should have turn them off.

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