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

2 comments
The script is in ServerScriptService.
That actually doesn't matter, be where it would be, without remove events/bindable events with FE on it won't work!