Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

DataStoreService doesn't save a value or something?

Asked by 5 years ago
Edited 5 years ago

-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)
0
Is this in studio? firestarroblox123 440 — 5y
0
It's in studio unpurrity 4 — 5y
0
Do you have "Access to API services" enabled? firestarroblox123 440 — 5y
0
Yes. If it's not enabled it will throw an error right? unpurrity 4 — 5y
View all comments (5 more)
0
Can I see the server logic of changeBool? firestarroblox123 440 — 5y
0
You need to give more info, or we can't help you. firestarroblox123 440 — 5y
0
Server logic as in the script for the remote event function when fired to server? Sorry for lack of info because I'm not really expert in these things... unpurrity 4 — 5y
0
Yes, I want to see what happens what the server does with the changeBool RemoteEvent. firestarroblox123 440 — 5y
0
I edited the question. I also point out that the BoolValue's Value doesn't change. unpurrity 4 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

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.

0
Make sense because the DataStore couldn't save with the lack of time. I checked it using print(). Thanks for the answer unpurrity 4 — 5y
Ad

Answer this question