-IM NOT GOOD IN EXPLAINING CUZ I SUCKS AT ENGLISH-
So I'm making a 1-player-only game and when the player joins, a local script will check if a BoolValue is true. If it's false (meaning that this is the first time the player has joined), another local script that will give welcome messages will be enabled and run. At the end of the same welcome local script, it will fire a RemoteEvent to the server to make the BoolValue's Value to true and then proceed to the next event and something unimportant...
This is the problem. When the player left, a DataStore will save that BoolValue's Value for the player but it still says false even after the server has changed the Value to true. Is the DataStore not saving at all? (Because I put a print() if the saving is a success but it doesn't appear in the Output)
Here's the DataStoreService Script with a bunch of print() (BaseScript):
local dts = game:GetService("DataStoreService") local DTWelcome = dts:GetDataStore("dtwelcome") game.Players.PlayerAdded:Connect(function(player) local statement = player:WaitForChild("Statements") local welcome = Instance.new("BoolValue") welcome.Name = "Welcome" welcome.Parent = player.Statements local data local success, errormessage = pcall(function() data = DTWelcome:GetAsync("1-"..player.UserId) end) if success then welcome.Value = data print("(JOINED)"..player.Name.."'s Welcome Bool is ") print(tostring(data)) else print("ERROR001 - Something happened while getting data...") warn(errormessage) end end) game.Players.PlayerRemoving:Connect(function(player) print("(LEFT)"..player.Name.."'s Welcome Bool is currently ") print(tostring(player.Statements.Welcome.Value)) local success, errormessage = pcall(function() DTWelcome:SetAsync("1-"..player.UserId,player.Statements.Welcome.Value) end) if success then print("Saved!") warn(errormessage) else print("ERROR002 - Something happened while saving data...") warn(errormessage) end end)
Here's a piece of the Welcome local script (At the end of the script):
changeBool:FireServer(player,"welcome",true)
This is what happens in the Output when you play the game tho:
(JOINED)Player's Welcome Bool is false 20:10:29.484 - ActivateCameraController did not select a module. (x2) (LEFT)Player's Welcome Bool is currently false 20:11:02.438 - Disconnect from 127.0.0.1|60492
Had to put it into Code Block so the line break works.
EDIT: I doubled-checked if the BoolValue's Value has changed when the welcome messages are done. It seems to be not changed so there might be something to do with this block of code:
local rep = game:GetService('ReplicatedStorage') local remoteevent = rep:WaitForChild("ChangeBool") remoteevent.OnServerEvent:Connect(function(player,argument,bool) if argument == "welcome" then player.Statements.Welcome.Value = bool end end)
If you run the game in studio the game server immediately exits when you leave, therefore there is not enough time for the datastore to complete it's process and the saving will be interrupted.
As a fallback you can also use game:BindToClose
and pass a function to that which loops over all the players currently in-game, and save the datastore values for them.