Tp achieve this, you can use a combination of a RemoteEvent and a ModuleScript that handles the saving and changing of the BoolValue for all players.
First, create a ModuleScript by right-clicking on your Workspace or ServerScriptService and selecting Insert Object > ModuleScript. Name this module “BoolValueHandler”.
Inside the BoolValueHandler module, you can define functions for saving and changing the BoolValue. Here’s an example implementation:
local BoolValueHandler = {}
function BoolValueHandler:SaveBoolValue(boolValue)
-- Save the current value of the BoolValue to a datastore or wherever you want to store it
end
function BoolValueHandler:ChangeBoolValue(boolValue, newValue)
-- Update the value of the BoolValue
boolValue.Value = newValue
-- Call the SaveBoolValue function to save the new value
BoolValueHandler:SaveBoolValue(boolValue)
-- Trigger a RemoteEvent to notify all players of the new value
game:GetService("ReplicatedStorage").BoolValueChanged:FireAllClients(boolValue.Name, boolValue.Value)
end
return BoolValueHandler
Now, create a RemoteEvent by right-clicking on your ReplicatedStorage and selecting Insert Object > RemoteEvent. Name this RemoteEvent “BoolValueChanged”.
Next, in a ServerScript (e.g., placed in ServerScriptService), you can handle the RemoteEvent and update the BoolValues for all players. Here’s an example implementation:
local BoolValueHandler = require(game:GetService("ServerScriptService").BoolValueHandler)
game:GetService("ReplicatedStorage").BoolValueChanged.OnServerEvent:Connect(function(player, boolValueName, newValue)
local boolValue = -- Find the BoolValue in your game based on the boolValueName
-- Call the function from the BoolValueHandler module to change the BoolValue
BoolValueHandler:ChangeBoolValue(boolValue, newValue)
end)
Finally, in each BoolValue that you want to save and change for everyone, you can add a Script to handle the value change and call the RemoteEvent to update all players. Here’s an example implementation:
local boolValue = script.Parent -- Assuming the script is placed inside the BoolValue
local BoolValueHandler = require(game:GetService("ServerScriptService").BoolValueHandler)
boolValue.Changed:Connect(function(newValue)
-- Call the function from the BoolValueHandler module to change the BoolValue
BoolValueHandler:ChangeBoolValue(boolValue, newValue)
end)
With this setup, whenever a BoolValue changes, it will trigger the BoolValueChanged RemoteEvent, which will then be handled on the server to update the BoolValues for all players. The BoolValueHandler module takes care of saving the new values and updating them accordingly.