Value doesn't set to false

Hello developers, Today I was making camera manipulation that ends when boolvalue is unchecked. But whenever I tried to stop manipulation it just won’t stop. the script is below, if anyone knows please tell me.

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

		if Humanoid and HMR then
			if Open.Value == 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()	
				Open.Value = true
				end
		else
			if Open.Value == true then 
				camera.CameraType = Enum.CameraType.Custom
				Open.Value = false
				print("Value is false")
			end
		end
	end
end)

good day.

Are you sure you aren’t adding an extra end)? Have you tried debugging your code, do the prints print?

1 Like

Your else statement is in the wrong place, if the humanoid or HRP doesn’t exist then it will check if the value is true.

How should I fix it then? I am new at scripting.

If there is no end then camera is glitching horribly, i tried everything i know. i made this post because i don’t know how to fix it.

If you’re running this once the character is spawned then you should wait for the Humanoid and the HumanoidRootPart instead of checking if they exist.

I did that and nothing hapened. still stuck.

Does nobody know what’s wrong/how to fix it?

I might be mistaken because I don’t understand much of camera manipulation, but the first thing I notice is that the only time this value will be put to false is when either the Humanoid or the HRM does not exist.

You have it like this:

if Humanoid and HMR then
     -- stuff
else -- this will only ever happen if Humanoid or HMR does not exist
     if Open.Value == true then
          Open.Value = false
     end
end

You say you’re new at scripting so I’ll try my best to help you out. But you’re saying that when you try to set the value to false it doesn’t work. That is because the value will only be false when there’s no Humanoid or HumanoidRootPart. I think this is an accident?
Can you let us know what exactly is supposed to happen to make this value false? Because now it only happens when you delete the humanoid.

when value is false camera should change to custom
Should i add “if not Humanoid and HMR then”?

Right now the camera changes to custom when it’s true and then the value becomes false
Is this the entire script or is there more at the top before “if Chatting == true then”?

what set the Open.Value to false or true server script or local. Is this script server or local?

the script is local is indeed.

so by this you mean that both scripts are local right?

yes, both of them are local, if I was making event, then i would use normal one.

Print humanoid and HMR and see what they get

scripts gets them, but when value tried to sets itself to false, it doesnt

i think the problem since If open.Value == true will only run if not humanoid and hmr

       if Humanoid and HMR then
			if Open.Value == 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()	
				Open.Value = true
				end
           elseif Open.Value == true then 
				camera.CameraType = Enum.CameraType.Custom
				Open.Value = false
				print("Value is false")
			end
		end

I already did that script before and it wasn’t working.