Datastore a boolvalue

Hello!
I am trying to datastore a boolvalues value but it won’t work

the script below is in serverscriptservice

local ds = game:GetService("DataStoreService")
local data = ds:GetDataStore("Characters")



game.Players.PlayerAdded:Connect(function(plr)
	local Character = Instance.new("Folder")
	Character.Name = "Characters"
	Character.Parent = plr
	
	--Test--
	local Character = Instance.new("BoolValue")
	Character.Name = "Test"
	Character.Parent = plr.Characters
	
	ds:SetAsync(plr.UserId, Character.Value)


game.Players.PlayerRemoving:Connect(function(plr)
	ds:SetAsync(plr.UserId, Character.Value)
	end)
end)

1 Like

You are using Set Async twice. It should be GetAsync(), in the player added event.

You need to use :GetAsync() to get the saved data (while :SetAsync() is used to save the data), also instead of ds you have to use the datastore you created which is data. You should use different variable names for the 2 instances you created. To get the data you should do something like:

local success, value = pcall(function()
	return data:GetAsync(plr.UserId)
end)

if success then
    Character.Value = value
end
2 Likes

You have 2 Character variables. Change the BoolValue variable to something else.

--Test--
	local Test = Instance.new("BoolValue")
	Test.Name = "Test"
	Test.Parent = Character -- The folder variable
	

And apply what was said above.
Data Stores – Roblox Documentation

You can also find useful information by searching keywords. (“loading data Roblox”, “saving data Roblox”…)

I did everything above and what you said it still doesn’t work but i think did something wrong this is my script now:

local ds = game:GetService("DataStoreService")
local data = ds:GetDataStore("Characters")



game.Players.PlayerAdded:Connect(function(plr)
	local Character = Instance.new("Folder")
	Character.Name = "Characters"
	Character.Parent = plr
	
	--Test--
	local Test = Instance.new("BoolValue")
	Test.Name = "Test"
	Test.Parent = plr.Characters
	local success, value = pcall(function()
		return data:GetAsync(plr.UserId, Test.Value)
	end)
	
	if success then
		Test.Value = value
	end
	

	game.Players.PlayerRemoving:Connect(function(plr)
	    data:SetAsync(plr.UserId, Test.Value)
	end)
end)
local ds = game:GetService("DataStoreService")
local data = ds:GetDataStore("Characters")

game.Players.PlayerAdded:Connect(function(plr)
	local Character = Instance.new("Folder")
	Character.Name = "Characters"
	Character.Parent = plr

	--Test--
	local Test = Instance.new("BoolValue")
	Test.Name = "Test"
	Test.Parent = Character
	local success, value = pcall(function()
		return data:GetAsync(plr.UserId)
	end)

	if success and value then
		Test.Value = value
	else
		Test.Value = false
	end
	
end)

game.Players.PlayerRemoving:Connect(function(plr)
	data:SetAsync(plr.UserId, plr.Characters.Test.Value)
end)