If Value Breaking

I previously had an Issue with the script taking around 3 seconds to load prior to any WaitForChild’s being added, but this wasn’t an Issue.
Recently I’ve had the Issue after updating the script to Include a toggle option of the script not working at all, I have no clue what’s causing this and as such haven’t been able to try any solutions.

No errors were printed In the console.

-- SETTINGS --

local sound = false -- If the script should play sound or not, you can change this sound by looking at the zoomscripts children and selecting one of the audios with the properties window open, then pasting In a asset ID --
local toggle = false -- If the zoom feature should be toggled or not --

local zoomFOV = 10 -- The FOV when zoomed, default Is 10 --

-- VARIABLES --

local zoomInSound = script.ZoomIn
local zoomOutSound = script.ZoomOut
local defaultFOV = game:WaitForChild("Camera").FieldOfView

-- SERVICES --

local uis = game:GetService("UserInputService")
local ts = game:GetService("TweenService")
local ss = game:GetService("SoundService")

-- SCRIPT --

debounce = false
	
uis.InputBegan:Connect(function(input, processed)
	
	if processed == true then return end
	
	if toggle == false then
		if input.KeyCode == Enum.KeyCode.Z then
			local ti = TweenInfo.new(0.1, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false)
			local pt = {
				FieldOfView = zoomFOV
			}
			local tween = ts:Create(game.Workspace.Camera, ti, pt)
			tween:Play()

			if sound == true then
				ss:PlayLocalSound(zoomInSound)
			end

			tween.Completed:Wait()
			debounce = false
		end
		
	elseif toggle == true then
		
		local active = false
		
		if input.KeyCode == Enum.KeyCode.Z and active == false then
			debounce = true
			local ti = TweenInfo.new(0.1, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false)
			local pt = {
				FieldOfView = zoomFOV
			}
			local tween = ts:Create(game.Workspace.Camera, ti, pt)
			tween:Play()

			if sound == true then
				ss:PlayLocalSound(zoomInSound)
			end

			tween.Completed:Wait()
			active = true
			debounce = false
		end
		
		if input.KeyCode == Enum.KeyCode.Z and active == true then
			debounce = true
			local ti = TweenInfo.new(0.1, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false)
			local pt = {
				FieldOfView = defaultFOV
			}
			local tween = ts:Create(game.Workspace.Camera, ti, pt)
			tween:Play()

			if sound == true then
				ss:PlayLocalSound(zoomInSound)
			end

			tween.Completed:Wait()
			active = false
			debounce = false
		end
		
	end
end)

uis.InputEnded:Connect(function(input, processed)
	if toggle == false then
		
		if processed == true then return end
		
		if input.KeyCode == Enum.KeyCode.Z then
			local ti = TweenInfo.new(0.1, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false)
			local pt = {
				FieldOfView = defaultFOV
			}
			local tween = ts:Create(game.Workspace.Camera, ti, pt)
			tween:Play()
			ss:PlayLocalSound(zoomOutSound)

			if sound == true then
				ss:PlayLocalSound(zoomOutSound)
			end

			tween.Completed:Wait()
			debounce = false

		end
	end
end)

I don’t see anywhere that you ever change toggle to be true.

You’re correct, that’s because I haven’t got around to testing It with the toggle value being true, I’ve been focusing on trying to figure out why It Isn’t working with the toggle value being false.

Sound like you need the help of the print command.

Add some print statements at key moments to help you track through the code to see where it is not executing.

1 Like

workspace.CurrentCamera is the camera being used by the LocalPlayer, not game.Camera or game.Workspace.Camera

Edit: You also don’t need to use WaitForChild in this case.

1 Like

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