Variable value won't change properly

While trying to add mobile support for camera movement on my game I have encountered a problem (the value of zooming does not change as intended)

Everytime the user stops pinching their device screen the value of zooming is supposed to change back to false but it does not for some reason (even though it does properly change the value of zooming to true when the player starts pinching their device screen)

Here’s the code snippet in which this problem occurs in:

local zooming = false
local c

UIS.TouchStarted:Connect(function(input, gpe)
	if gpe then return end
	local originalPos = {mouse.X, mouse.Y}
	local xInterval
	local yInterval
	
	c = UIS.TouchMoved:Connect(function(touch, gpe)
		if gpe then return end
		if zooming == true then return end
		xInterval = (mouse.X - originalPos[1]) * 0.15
		yInterval = (mouse.Y - originalPos[2]) * 0.15

		cam.CFrame = CFrame.new(math.clamp(-xInterval + cam.CFrame.X, -22, 220), cam.CFrame.Y, math.clamp(-yInterval * 1.67 + cam.CFrame.Z, 25, 252)) * cam.CFrame.Rotation
		
		originalPos = {mouse.X, mouse.Y}
	end)
	
	UIS.TouchEnded:Connect(function(input, gpe)
		if gpe then return end
		c:Disconnect()
	end)
end)

local origScale = 0
UIS.TouchPinch:Connect(function(touchPos, scale, vel, state, gpe)
	if state == Enum.UserInputState.End then 
		zooming = false
	end
	if gpe then return end
	zooming = true
	
	if origScale >= scale and cam.CFrame.Y >= 25 then 
		cam.CFrame += Vector3.new(0, -2, -2)
	elseif origScale < scale and cam.CFrame.Y <= 120 then
		cam.CFrame += Vector3.new(0, 2, 2)
	end
	
	origScale = scale
end)

The TouchMoved event can’t proceed due to the fact that the zooming variable cannot properly change back to false after a TouchPinch has ended

Any help would be appreciated

I believe you need to return after setting zooming to false; otherwise, it will be set to true regardless of pinch state.

Yep I forgot to include that in the code lol

Thanks for the help

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