Hello! i’m doing DataSaving system for my game. DataSaving system saving Player Settings. And theres setting for mute/unmute songs in-game. When i set BoolValue to true, Data Saving won’t work.
Script:
local DataStore = game:GetService("DataStoreService")
local SettingsData = DataStore:GetDataStore("PlayerSettingsData")
game.Players.PlayerAdded:Connect(function(Player)
local PlayerSettings = Instance.new("Folder")
PlayerSettings.Parent = Player
PlayerSettings.Name = "PlayerSettings"
local Musics = Instance.new("BoolValue")
Musics.Name = "Musics"
Musics.Value = SettingsData:GetAsync(Player.UserId) or true
Musics.Parent = PlayerSettings
SettingsData:SetAsync(Player.UserId, PlayerSettings.Musics.Value)
game.Players.PlayerRemoving:connect(function()
SettingsData:SetAsync(Player.UserId, PlayerSettings.Musics.Value)
end)
end)
You should not be using PlayerRemoving inside of the PlayerAdded handler. PlayerRemoving will fire for any player that leaves the game.
That being said, your initial logic to load the value will fail: SettingsData:GetAsync(Player.UserId) or true. That will always result in true because how the conditional statement works. Check explicitly for the nil value:
local loaded = SettingsData:GetAsync(player.UserId)
Musics.Value = if loaded ~= nil then loaded else true