Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to Make this script to save 2 bool values and create?

**How to Make this script to save 2 bool values and create? **

local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("BoolSave")

game.Players.PlayerAdded:connect(function(player)
 local folder = Instance.new("Folder",player)
 folder.Name = "stats"
 local bool = Instance.new("BoolValue",folder)
 bool.Name = "BoolValue"

 bool.Value = ds:GetAsync(player.UserId) or false
 ds:SetAsync(player.UserId, bool.Value)
end)


game.Players.PlayerRemoving:connect(function(player)
 ds:SetAsync(player.UserId, player.stats.BoolValue.Value)
end)

2 comments

0

use tables, instead of for example bool.Value make it {bool.Value, bool2.Value}, to access, it simply do Bool1 = Saved[1] Bool2 = Saved[2] (or something like that)

0

i tried its dont works

1 answer

✓ Accepted answer

Instead of using game.Players.PlayerRemoving you should use bool.Change

if i have understood you correctly you want to save 2 values like this:

local ds1 = game:GetService("DataStoreService"):GetDataStore("BoolSave")
local ds2 = game:GetService("DataStoreService"):GetDataStore("BoolSave")

game.Players.PlayerAdded:Connect(function(player)
	local stats = Instance.new("Folder", player)
	stats.Name = "Stats"
	
	local bool1 = Instance.new("BoolValue", player)
	bool1.Name = "BoolValue1"
	bool1.Value = ds1:GetAsync(player.UserId) or false
	
	local bool2 = Instance.new("BoolValue", player)
	bool2.Name = "BoolValue2"
	bool2.Value = ds2:GetAsync(player.UserId) or false
	
	bool1.Changed:Connect(function()
		bool1:SetAsync(player.UserId, bool1.Value)
		
	end)
	
	bool2.Changed:Connect(function()
		bool2:SetAsync(player.UserId, bool2.Value)
		
	end)
	
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.