Heya!! VERY new to scripting here. I haven't learnt anything about Lua grammar and what most of the values do etc. so I am trying to get there by working on small mechanics.
I am attempting to make a script in which holding left shift increases player speed and increases the Field Of View.
This is what I have:
local UIS = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local camera = workspace.CurrentCamera
local TweenService = game:GetService("TweenService")
local FOV = camera.FieldOfView
FOV = 70
local sprintstart = TweenInfo.new(0.3, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
local sprintend = TweenInfo.new(0.3, Enum.EasingStyle.Sine, Enum.EasingDirection.In)
local startgoal = {}
startgoal.FOV = 90
local endgoal = {}
endgoal.FOV = 70
local starttween = TweenService:Create(FOV, sprintstart, startgoal)
local endtween = TweenService:Create(FOV, sprintend, endgoal)
UIS.InputBegan:Connect(function(input, gameProcessedEvent)
if input.KeyCode == Enum.KeyCode.LeftShift then
player.Character.Humanoid.WalkSpeed = 36
starttween:Play()
end
end)
UIS.InputEnded:Connect(function(input, gameProcessedEvent)
if input.KeyCode == Enum.KeyCode.LeftShift then
player.Character.Humanoid.WalkSpeed = 16
endtween:Play()
end
end)
This only results in the error 'Unable to cast value to object', which I can probably assume is just a grammar area, or something I haven't defined. Sadly I am too amateur to figure this one out, so if any of you guys could help me that would be great! Thank you!!
EDIT: the error only came up once I attempted to tween the FOV, the script worked fine without the tweening.

4 comments
Here is your problem(maybe), TweenService:Create(FOV, sprintstart, startgoal) instead of FOV, maybe it should be the camera.
that brought me back to 'attempting to index nil (fieldofvalue). but thanks anyways!
Sorry for the really long reply, but the error means that the arguments you passed in was a value instead of an object.
FOV is a value and returns a float not an object, hence the error!