Camera Cframe not working because 2 scripts use it

Hello Developers.
In my game, there are more scripts that use camera tweening with CFrame.
and in the script, there is “else” when you are done with something so camera goes to custom. And if one script say’s camera is scriptable and the other camera is custom, It just brokes. If anyone has a clue how to prevent overlapping scripts please reply,

good day.

1 Like

You could just combine them into one script instead of two which would allow them to communicate a lot better.

You would need to restructure your scripts or keep track of when a camera is being manipulated. There are many solutions to this issue.

If you want to use the debounce method you could set the camera manipulated variable after you change it to scriptable, then when you are done with the tween or setting the camera values change the variable to false.

Then in your camera manipulation sections of code do a check for if IsManipulated == false then proceed.

Just a general idea, and one of many solutions.

I tried with debounce, but after the camera just gets stuck. and I don’t have clue how to fix it. I am gonna put the script here, and if you know the problem please reply, thanks

if Chatting == true then
	local Humanoid = detectedNPC:FindFirstChild("Humanoid")
	local HMR = detectedNPC:FindFirstChild("HumanoidRootPart")

	if Humanoid and HMR then
		if Debounce == false then
		   camera.CameraType = Enum.CameraType.Scriptable
			TS:Create(camera, TweenInfo.new(1), {CFrame = HMR.CFrame * CFrame.new(0, 1.5, -4) * CFrame.Angles(0, math.pi, 0)}):Play()	
			Debounce = true
			end
 elseif
	 Debounce == true then 
			camera.CameraType = Enum.CameraType.Custom
			Debounce = false
		end
	end
end)

have a good day :slight_smile:

1 Like
if Chatting == true then
	local Humanoid = detectedNPC:FindFirstChild("Humanoid")
	local HMR = detectedNPC:FindFirstChild("HumanoidRootPart")

	if Humanoid and HMR then
		if Debounce == false then
			camera.CameraType = Enum.CameraType.Scriptable
			TS:Create(camera, TweenInfo.new(1), {CFrame = HMR.CFrame * CFrame.new(0, 1.5, -4) * CFrame.Angles(0, math.pi, 0)}):Play()	
			Debounce = true
		elseif Debounce == true then 
			camera.CameraType = Enum.CameraType.Custom
			Debounce = false
		end
	end
end

This is your code fixed up. It may not fix your issue but try with your code fixed up first.

I tried with the script you gave me and added debounce on other script but the camera is glitching a lot. also, do you need to have “else” or “elseif” in debounce for it to work.

This is better because the spacing is fixed, but a debounce requires a wait() call. This situation shouldn’t require a debounce anyway. You need to combine your camera scripts so only one script is playing with the camera. I cannot find the immediate issue from just this code snippet other than the debounce not working.

I cannot do that, due to they are totally different scripts that use camera manipulation in only one part.

Could I maybe instead of Debounce use BoolValue so it check if camera tweening is true or false

You are correct. I just fixed the code that was provided (not just spacing) but the if else if were incorrect. I did not provide the solution with that code. There are plenty of ways to handle the current problem. I was merely providing suggestions, not writing the code out.

The general idea is to set something to say “Hey, I’m manipulating the camera right now, nobody else can until I’m done”. That could be by combining camera scripts into a single area, debounces, what have you. A boolvalue would be the same concept as a bool variable.

The problem you have currently with your bool variable(Debounce) is that you have it in one script. You have to set the debounce from wherever you manipulate the camera. So yes, the boolvalue will be easy to setup to read from and set in multiple scripts. Otherwise, make a cross script value through module script or BindableEvent.