So I recently reviewed my script that handles server shutdowns and noticed it was only working when the server closed. The close functions came from youtuber Gnomecode and his datastore video. When the game shutdown, it closes in less than 20 seconds then calls the function.
I have tried removing the modules but that did not work.
--- DataStores
local DS = game:GetService("DataStoreService")
local KnifeDuplicatesData = DS:GetDataStore("KnifeDuplicates")
local DataStore = DS:GetDataStore("Money")
local VehicleDataStore = DS:GetDataStore("Vehicles")
local SkillsData = DS:GetDataStore("Skills")
local KnivesData = DS:GetDataStore("Knives")
local EffectData = DS:GetDataStore("KnifeEffects")
local GarageItemDataStore = DS:GetDataStore("GarageItems")
--- DataModules
local DuplicateDataSave = require(script.Parent.DuplicateSave.DataStore)
local EffectSave = require(script.Parent.EffectSave.DataStore)
local KnifeSave = require(script.Parent.KniveSave.DataStore)
local VehicleSave = require(script.Parent.VehicleSave.DataStore)
local OtherSave = require(script.OtherSave)
local runService = game:GetService("RunService")
function ShutdownSave(player)
local playerUserId = "Player_" .. player.UserId --Gets player ID
DuplicateDataSave.SaveData(player,KnifeDuplicatesData,playerUserId,player.KnifeDuplicates,"Duplicates")
KnifeSave.SaveData(player,KnivesData,playerUserId,player.Knives,"Knives")
VehicleSave.SaveData(player,VehicleDataStore,playerUserId,player.Vehicles,"Vehicles")
OtherSave.SaveMoney(player,DataStore)
OtherSave.Save(player,SkillsData,playerUserId,player.Skills)
OtherSave.Save(player,EffectData,playerUserId,player.KnifeEffects)
OtherSave.SaveVehicleData(player,GarageItemDataStore)
print("Shutdown Save Data")
end
function GameClosing(reason)
if runService:IsStudio() then return end
print("Shutting server down for: ",reason.Name)
local players = game.Players:GetPlayers()
for i, v in ipairs(players) do
task.spawn(function()
ShutdownSave(v)
end)
end
end
game:BindToClose(GameClosing)
Please help me understand what is the problem