FOV saving doesn't work

Hello, I was trying to make a FOV saving script but apparently, it doesn’t work. I tried to search on the internet but couldn’t find anything. I appreciate any help.
This is the script:

local DataStoreService = game:GetService("DataStoreService")
local FieldOfViewDataStore = DataStoreService:GetDataStore("FieldOfViewDataStore")

game.Players.PlayerAdded:Connect(function(plr)
	local data
	local success, errormessage = pcall(function()
		data = FieldOfViewDataStore:GetAsync(plr.UserId.."-fov")
	end)
	
	if success then
		game.Workspace.CurrentCamera.FieldOfView = data
	else
		print("Error while getting "..plr.Name.." FOV data")
		warn(errormessage)
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
	local success, errormessage = pcall(function()
		FieldOfViewDataStore:SetAsync(player.UserId.."-fov",game.Workspace.CurrentCamera.FieldOfView)
	end)
	
	if success then
		print("FOV saved for "..player.Name)
	else
		print("FOV data not found for "..player.Name)
		warn(errormessage)
	end
end)
1 Like

You are setting the field of view from the server, which does not work. You need to:

  • Have the setting change and apply on the client
  • Have the client inform the server what the new setting value is (when changed)
  • Have the server tell the client what the saved value is (when the player joins the game)

This means you should have a local script somewhere reactive to this.

2 Likes

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