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)