Attempt to index number with 'FieldOfView'

  1. What do you want to achieve?
    Kind of a pls donate animation
    changes the field of view by a little bit
    then tweens back to normal

  2. What is the issue? i get an error saying attempt to index number with ‘FieldOfView’

  3. What solutions have you tried so far? wrapping it in spawn functions and pcall’s

-- Variables -- 
local CurrentSlot = nil
local Player = game:GetService("Players").LocalPlayer
local Mouse = Player:GetMouse()
local UserInputService = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")
local PlacementPosition = workspace:WaitForChild("Connect4"):WaitForChild("Positions")
local CurrentCamera = workspace.CurrentCamera
local HighestRow = 7
local Controls = require(Player.PlayerScripts:WaitForChild("PlayerModule")):GetControls()
Controls:Disable()
-- Information --
local Slider = nil
local coincreate = game.ReplicatedStorage:WaitForChild("Templates"):WaitForChild("Coin"):Clone()
coincreate.Parent = workspace.Connect4
Slider = coincreate

-- Functions --
local function Changed()
	spawn(function()
		local old = 70
		CurrentCamera.FieldOfView = CurrentCamera.FieldOfView - 5
		wait(0.1)
		TweenService:Create(CurrentCamera, TweenInfo.new(1, Enum.EasingStyle.Quint), {
			FieldOfView = old
		}):Play()
	end)
end
local function ChangeSlot(new)
	if new < HighestRow then
		CurrentSlot = new
	elseif new == HighestRow then
		CurrentCamera = 1
	end
	if Slider then
		local success, errormessage = pcall(function()
			Changed()
		end)
		if not success then
			warn(errormessage)
		end
		TweenService:Create(Slider, TweenInfo.new(0.5, Enum.EasingStyle.Quint), {
			CFrame = CFrame.new(PlacementPosition.Choosing[CurrentSlot].Position)
		}):Play()
	end
end

ChangeSlot(1)
-- Main Script --
UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
	if gameProcessedEvent then
		return
	end
	if input.KeyCode == Enum.KeyCode.D and UserInputService:GetFocusedTextBox() == nil then
		ChangeSlot(CurrentSlot + 1)
	end
	if input.KeyCode == Enum.KeyCode.A and UserInputService:GetFocusedTextBox() == nil then
		ChangeSlot(CurrentSlot - 1)
	end
end)
1 Like

You redefine the CurrentCamera variable to 1

3 Likes

Yup, as @HugeCoolboy2007 says.

The CurrentCamera initialisation on line 8:

local CurrentCamera = workspace.CurrentCamera

Is being trashed when you re-initialise it to 1 on line 33, like so:

CurrentCamera = 1

Now CurrentCamera is equal to 1 and will have none of the properties associated with a camera class like FieldOfView for you to manipulate. 1 is simply 1, it knows nothing about FieldOfView etc…

1 Like

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