Then we need the value, and here, we will use arguments !
So in your local script, you change the gui to dark or to light but you canât change the playerâs value on the local script becaue it will not be considerated by the server.
If a value is changed by a client (by a local script) it will not be considerated by the server.
If you want an exemple, do you see games, where there are walls between maps.
Some players can pass through if they buy the map but other canât.
It because the wall exists on the client but not on the server.
So itâs the same here, if you change the value of lighting it will not affect the server, so just seperate the result doing something like this.
You have your Gui, and i think there is two button, one for light and one for dark, so if light is pressed, fire the server and send as an argument a string like âDARKâ or âLIGHTâ to the server.
So your local script looks like this :
local event = game.ReplicatedStorage:WaitForChild("YourRemoteEvent")
darkButton.MouseButton1Click:Connect(function()
event:FireServer("DARK") -- it will send the player as argument 1 and the side (Light or dark) as a second argument.
end
lightButton.MouseButton1Click:Connect(function()
event:FireServer("LIGHT")
end
-- Here you can add you lines wich change the text of the UI ect...
So now, you have to update the server and to save it, you can do it like this :
local DSS = game:GetService("DataStoreService"):GetDataStore("DataStore1") -- Name it whatever you like
local event = game:GetService("ReplicatedStorage"):WaitForChild("YourRemoteEvent")
-- Here we will create the key of the save, you need a unique key for each player so we will use his UserId so:
local key = "Side-"..plr.UserId -- This will concatinate the string ("Side-" with the player.UserId, it will gives something like this, "Side-2452865896"
-- Now make the function run when the server is fired --
event.OnServerEvent:Connect(function(player, side) -- So here you get as arguments the player and the side, side will be equal to "DARK" if the player choose Dark or "LIGHT" if he shose light.
-- Now you can change the value and save it --
-- We have to find the player value doing :
local value = player.Lightning
-- Now let's change the value of the lightning on the server, so we have to do:
if side == "DARK" then
value.Value = 1
elseif side == "LIGHT" then
value.Value = 2
end
-- Now you can save it :
-- We'll add this line to avoid the script to crash if it faces an error:
local success, errormessage = pcall(function() -- and inside you can save the value in normal DSS or it is a bit different for DSS2
DSS:SetAsync(key, value.Value) -- Here we will save behind the key we created before the value so 1 for the DARK and 2 for the light. Now when the player joins the game, you have to give back the value of Lightning and if it equal to 0 you make the player choose and if it equals to 1 you change the UI to dark mode and if it equals to 2 you change it to light mode.
end)
If you have question ask them, and i can come help you on a sharred place!