I've been working on this for like 5 days and can't figure it out because I have tiny brain. I've asked for help here multiple times but no matter what I do it won't work. I know the saving won't work because the data loading works completely fine.
Here's the code I have:
-- Written by MattVSNNL
local PlayersService = game:GetService("Players")
local dataStoreService = game:GetService("DataStoreService")
local boolDataStore = dataStoreService:GetDataStore("BoolDataStore")
PlayersService.PlayerAdded:Connect(function(player)
local onMenu = Instance.new("BoolValue")
onMenu.Name = "onMenu"
onMenu.Parent = player
local onMenuData = nil
pcall(function()
onMenuData = boolDataStore:GetAsync(player.UserId.."-onMenu")
end)
if onMenuData ~= nil then
onMenu.Value = onMenuData
else
onMenu.Value = true
end
end)
local bindableEvent = Instance.new("BindableEvent")
PlayersService.PlayerRemoving:Connect(function(player)
pcall(function()
boolDataStore:SetAsync(player.UserId.."-onMenu", player.onMenu.Value)
end)
bindableEvent:Fire()
print("Saved!")
end)
game:BindToClose(function()
while #PlayersService:GetPlayers() > 0 do
bindableEvent.Event:Wait()
wait()
end
end)

2 comments
Could you try printing the success and error message returned from the pcall? (local success, errorMessage = pcall(...)
^Also you aren't ever calling the save function inside of your game:BindToClose function.