In studio when I reset my character after I changed it’s fov it stays the same which is good but, if I change it in the roblox player and reset my character it goes back to it’s default fov.
Video:
Script:
local Player = game:GetService("Players").LocalPlayer
local Camera = workspace.CurrentCamera
local TextBox = script.Parent
Player:SetAttribute("setFOV", Camera.FieldOfView)
local function updateFOV(newFOV)
newFOV = math.clamp(newFOV, 70, 120)
Player:SetAttribute("setFOV", newFOV)
Camera.FieldOfView = newFOV
end
TextBox.FocusLost:Connect(function(returnPressed)
if not returnPressed then return end
if TextBox.Text:match("^%d+$") then
updateFOV(tonumber(TextBox.Text))
end
end)
Player.CharacterAdded:Connect(function()
wait(0.1)
local storedFOV = Player:GetAttribute("setFOV")
if storedFOV then
Camera.FieldOfView = storedFOV
end
end)
I think studio is on something, some things are glitching and I don’t know why. Some things are doing well in studio but once I launch it through the player stuff isn’t working. I changed the ScreenGui from Disabled to Enabled back to Disabled and now the text button isn’t appearing in the launcher but it is in studio.
Ohhh your script is setting the attribute for setFov at the start, which is what it causing this problem.
Code:
local Player = game:GetService("Players").LocalPlayer
local Camera = workspace.CurrentCamera
local TextBox = script.Parent
local function updateFOV(newFOV)
newFOV = math.clamp(newFOV, 70, 120)
Camera.FieldOfView = newFOV
end
TextBox.FocusLost:Connect(function(returnPressed)
if not returnPressed then return end
if TextBox.Text:match("^%d+$") then
updateFOV(tonumber(TextBox.Text))
end
end)
Make sure to turn ResetOnSpawn to false, it worked for me.
I think you should store that value in ReplicatedStorage under a (can be created) Settings folder. When the FOV is changed, set the value to the changed FOV. Then once the player resets, the script can read back the value from the stored FOV, thus keeping the FOV intact.
Something like:
local Player = game:GetService("Players").LocalPlayer
local Camera = workspace.CurrentCamera
local TextBox = script.Parent
local FOV = game.ReplicatedStorage.Settings:FindFirstChild("FOV")
if not FOV then
FOV = Instance.new("IntValue"); FOV.Value = 70; FOV.Name = "FOV"; FOV.Parent = game.ReplicatedStorage.Settings
end
local function updateFOV(newFOV)
FOV.Value = newFOV
newFOV = math.clamp(newFOV, 70, 120)
Camera.FieldOfView = newFOV
end
updateFOV(FOV.Value)
TextBox.FocusLost:Connect(function(returnPressed)
if not returnPressed then return end
if TextBox.Text:match("^%d+$") then
updateFOV(tonumber(TextBox.Text))
end
end)
This should (in theory) fix that problem. Also, this also works with ResetOnSpawn set to true.
I can’t help but notice the number of errors in the output…
Maybe try adding a WaitForChild() on the character highlight?
Maybe also try to add an if statement on the humanoid root part, for example:
if character:FindFirstChild("HumanoidRootPart") then
--do the functions
end
Leaving a lot of logs on the console can hurt performance, especially on mobile. A popular game like (used-to-be) Jenga tower did this mistake by printing things every time a player is detected inside the death part (which is every heartbeat), which obliterated many people’s fps on mid-round.