local ds = game:GetService("DataStoreService") local bool = ds:GetDataStore("BoolSaving?") game.Players.PlayerAdded:Connect(function(plr) local boolValue = Instance.new("BoolValue") boolValue.Parent = plr boolValue.Name = "BoolValue" local boolValue1 = Instance.new("BoolValue") boolValue1.Parent = plr boolValue1.Name = "BoolValue1" boolValue.Value = bool:GetAsync(plr.UserId) or false boolValue1.Value = bool:GetAsync(plr.UserId) or false end) game.Players.PlayerRemoving:Connect(function(plr) bool:SetAsync(plr.UserId, plr.BoolValue.Value) bool:SetAsync(plr.UserId, plr.BoolValue1.Value) end)
For some reasons, this script doesnt work, idk why. Also im not really good at datastore so please show me the fixed script if you know.
local ds = game:GetService("DataStoreService") local bool = ds:GetDataStore("BoolSaving") game.Players.PlayerAdded:Connect(function(plr) local boolValue = Instance.new("BoolValue") boolValue.Parent = plr boolValue.Name = "BoolValue" local boolValue1 = Instance.new("BoolValue") boolValue1.Parent = plr boolValue1.Name = "BoolValue1" boolValue.Value = bool:GetAsync(plr.UserId.."-bool") or false boolValue1.Value = bool:GetAsync(plr.UserId.."-bool1") or false end) game.Players.PlayerRemoving:Connect(function(plr) bool:SetAsync(plr.UserId.."-bool", plr.BoolValue.Value) bool:SetAsync(plr.UserId.."-bool1", plr.BoolValue1.Value) end)
SUGGESTION: Put the boolValue thing under a pcallfunction so if got error the script wont break
also im notsure if data stores can have qn marks so i js removed it and i also edited other stuff u can take a look
Datastores can only store up to 1 value. If you'd like to increase that number, use tables.
local ds = game:GetService("DataStoreService") local bool = ds:GetDataStore("BoolSaving?") game.Players.PlayerAdded:Connect(function(plr) local boolValue = Instance.new("BoolValue") boolValue.Parent = plr boolValue.Name = "BoolValue" local boolValue1 = Instance.new("BoolValue") boolValue1.Parent = plr boolValue1.Name = "BoolValue1" local data local success, err = pcall(function() data = bool:GetAsync(plr.UserId) end) if not success then warn(err) return end boolValue.Value = data.Value or false boolValue1.Value = data.Value1 or false end) game.Players.PlayerRemoving:Connect(function(plr) local data = { Value = plr.BoolValue.Value; Value1 = plr.BoolValue1.Value; } local success, err = pcall(function() bool:SetAsync(plr.UserId, data) end) if not success then warn(err) end end)