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

DataStore saves in studio, but not in servers?

Asked by
znepb 17
6 years ago
Edited 6 years ago

My DataStore for settings is not saving properly, and I have no clue why. I've tried changing keys and DataStore names, and that doesn't seem to be doing anything. Loading works fine because I tried editing it through a plugin that lets you edit your DataStores, so I know it's not the loading part of the script. I have an AutoSave that uses the spawn() function, I don't know if that is conflicting with the player left, but I don't know.

Here my saving part of my code.

PlayerRemoving save:

--The DataStore key is using:
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("Settings")

local settings = player:WaitForChild("Settings")

local key = "User-"..player.userId -- User-(playerid) is what I am currently using, I was using player-(playerid) before.

local valuesToSave = {
    settings.MusicEnabled.Value, settings.MusicVolume.Value
}
DataStore:SetAsync(key, valuesToSave)
print("Stats successfuly saved!")

Autosave:

spawn(function()
    while wait(autosaveInterveal) do
        print("Now autosaving!")
        for i, player in pairs(game.Players:GetPlayers()) do

            local settings = player:WaitForChild("Settings")

            local key = "User-"..player.userId

            local valuesToSave = {
                settings.MusicEnabled.Value, settings.MusicVolume.Value
            }
            DataStore:SetAsync(key, valuesToSave)
        end
        print("Autosave complete")
    end
end)

All of the code is in the same script.

Edit: My game is FilteringEnabled.

Thanks for the help! ~Marco

1 answer

Log in to vote
0
Answered by 6 years ago

I don't know where your script is but, since your game is using filtering enabled I would recommend using Remote Events/Bindable Events to do so. If you don't know how there 2 work just go to this links: (They helped me alot)

https://www.youtube.com/watch?v=jQ0iClyt_zA&t=497s

https://www.youtube.com/watch?v=C0qQ4lDa3t0&t=526s

--//I don't recomend these because they are too confusing!\\--

http://wiki.roblox.com/index.php?title=Remote_Events_and_Functions

http://wiki.roblox.com/index.php?title=API:Class/BindableEvent

0
The script is in ServerScriptService. znepb 17 — 6y
0
That actually doesn't matter, be where it would be, without remove events/bindable events with FE on it won't work! wilsonsilva007 373 — 6y
Ad

Answer this question