Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can I run this (coroutine) function over again?

I've already tried a load of methods including wrap in order to try and have this function run multiple times so long as the Value is true. It only runs once however and every time I use 'coroutine.wrap', it outputs something about thread values. I just want the camera to rotate as shown below while the value is true.

-- CODE BELOW --

local SelectedVehicle = workspace:WaitForChild('Cessna')

Config.MenuActive.Changed:Connect(function(Value)
	print(Value)
	if Value == true then
		DealershipCam = coroutine.create(function()
			Camera.CameraSubject = SelectedVehicle
			
			while wait() do
				local SideVector = (Camera.CoordinateFrame - Camera.CoordinateFrame.p) * Vector3.new(1,0,0)
				Camera.CoordinateFrame = CFrame.new(Camera.CoordinateFrame.p + (SideVector * .05))
				Camera.Focus = SelectedVehicle.PrimaryPart.CFrame
				if Config.MenuActive.Value == false then
					coroutine.yield(DealershipCam)
					break
				end
			end
		end)
		coroutine.resume(DealershipCam)
	end
end)

1 answer

If you don't understand threads, you shouldn't be using coroutines. Coroutines are very rarely needed to perform tasks on Roblox. I have not found a good use scenario in any common project I've done over the years.

That said, this is my interpretation of your script (Untested, and I'm assuming that your math for positioning the camera is correct):

local selected = game.Workspace:WaitForChild("Cessna");

Config.MenuActive.Changed:connect(function(value)
	print(value);
	while(Config.MenuActive.Value == true)do
		Camera.CameraSubject = selected;
		local SideVector = (Camera.CoordinateFrame - Camera.CoordinateFrame.p) * Vector3.new(1,0,0)
                Camera.CoordinateFrame = CFrame.new(Camera.CoordinateFrame.p + (SideVector * .05))
                Camera.Focus = SelectedVehicle.PrimaryPart.CFrame
		wait();
	end
end)

3 comments

0

Everything works without the if statements and changed functions basically.

0

The camera does change subject and it constantly focuses on the object as it forces me to view it when I move the camera. However, it just doesn't move around with the change function and if statement

0

Is MenuActive a BoolValue Object?

This discussion is preserved as it was. New answers, comments, and votes are closed.