hello yet again
i have a script that, given an input of the Q key, increases FOV via a for loop that adds + 1 each 0.025 second.
said player can die, and in such scenario the player respawns with FOV that differs from default.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
player’s FOV
any idea if i could prevent that? i tried adding an if statement that then breaks the loop, but it brought similar results. here’s the script.
local inputservice = game:GetService("UserInputService")
local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local replicatedstorage = game:GetService("ReplicatedStorage")
local active = false
local origwalkspeed = nil
local camera = game:GetService("Workspace").CurrentCamera
local sounds = game:GetService("Workspace").Sounds
local speedupamount = 8
local abilityduration = 2.5
local addFOVamount = 30
inputservice.InputBegan:Connect(function(input, isTyping)
if not active then
origwalkspeed = character.Humanoid.WalkSpeed
end
if active then
return
end
if isTyping then
return
end
if input.KeyCode == Enum.KeyCode.Q then
active = true
character.Humanoid.WalkSpeed = origwalkspeed + speedupamount
sounds["pumpkin_drop.wav"].Playing = true
for i = 1, addFOVamount do
camera.FieldOfView += 1
task.wait(0.025)
end
task.wait(abilityduration)
for i = 1, addFOVamount do
camera.FieldOfView -= 1
task.wait(0.025)
end
character.Humanoid.WalkSpeed = origwalkspeed
active = false
end
end)
^^^^^^
(local script)
also, any feedback on the script is welcome.
I dont know how to change the players FOV
but you would do it inside there.
There may not be brackets after the ends, but i forgot whether or not there were.
If you can only change it in a local script, use a remote event, and fire it to the player.
Assuming this is a LocalScript in StarterCharacterScripts,
-- your other declarations
local origwalkspeed = character.Humanoid.WalkSpeed
local origfov = camera.FieldOfView
local tweenservice = game:GetService("TweenService")
local speedupamount = 8
local abilityduration = 2.5
local addFOVamount = 30
local to = tweenservice:Create(camera, TweenInfo.new(1), {FieldOfView = camera.FieldOfView + addFOVamount})
local from = tweenservice:Create(camera, TweenInfo.new(1), {FieldOfView = origfov})
inputservice.InputBegan:Connect(function(input, isTyping)
if active or isTyping then
return
end
if input.KeyCode == Enum.KeyCode.Q then
active = true
character.Humanoid.WalkSpeed += speedupamount
sounds["pumpkin_drop.wav"]:Play()
to:Play()
if to.Completed:Wait() == Enum.PlaybackState.Completed then
task.wait(abilityduration)
character.Humanoid.WalkSpeed = origwalkspeed
from:Play()
end
active = false
end
end)
character.Humanoid.Died:Connect(function()
to:Cancel()
camera.FieldOfView = origfov
end)
I went through your script and tightened it up to do as you wish, but I never hit that error in the first place with your first script. All I can think is somehow the player was respawning so fast the loop to reset the camera wasn’t finished. I tested in StarterCharacterScripts and StarterPlayerScripts.
local inputservice = game:GetService("UserInputService")
local player = game:GetService("Players").LocalPlayer
local camera = game:GetService("Workspace").CurrentCamera
local sounds = game:GetService("Workspace").Sounds
local defaultFOV = camera.FieldOfView
local speedupamount = 8
local abilityduration = 2.5
local addFOVamount = 30
local active = false
local origwalkspeed
local function setup(char)
origwalkspeed = char:WaitForChild("Humanoid").WalkSpeed
camera.FieldOfView = defaultFOV
end
setup(player.Character or player.CharacterAdded:Wait())
player.CharacterAdded:Connect(setup)
inputservice.InputBegan:Connect(function(input, isTyping)
if isTyping or active or not player.Character then return end
if input.KeyCode == Enum.KeyCode.Q then active = true
local hum = player.Character:FindFirstChild("Humanoid")
if hum then hum.WalkSpeed = origwalkspeed + speedupamount
end sounds["pumpkin_drop.wav"].Playing = true
for i = 1, addFOVamount do
if not player.Character or not player.Character.Parent then break
end camera.FieldOfView += 1 task.wait(0.025)
end task.wait(abilityduration)
for i = 1, addFOVamount do
if not player.Character or not player.Character.Parent then break
end camera.FieldOfView -= 1 task.wait(0.025)
end
if hum then hum.WalkSpeed = origwalkspeed
end camera.FieldOfView = defaultFOV
active = false
end
end)