Boolean Value Data Save Help

My data save for boolean values is not working…

local DataStoreService = game:GetService("DataStoreService")

local ds = DataStoreService:GetDataStore("datatest")

game.Players.PlayerAdded:Connect(function(plr)
	local axes = Instance.new("Folder",plr)
	axes.Name = "axes"
	local Homemadeaxe = Instance.new("BoolValue",axes)
	Homemadeaxe.Name = "Homemadeaxe"
	local Normalaxe = Instance.new("BoolValue",axes)
	Normalaxe.Name = "Normalaxe"
	
	local dataofuser = ds:GetAsync(plr.UserId)
	if dataofuser ~= nil then -- anything but nil
		print("Found data for " .. plr.Name)
		Homemadeaxe.Value = ds[1]
		Normalaxe.Value = ds[2]
	else
		print("Replacing no data with new data.")
		Homemadeaxe = true
		Normalaxe = false
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	local datasave = {}
	table.insert(datasave, plr:WaitForChild("Homemadeaxe"):WaitForChild("BoolValue").Value)
	table.insert(datasave, plr:WaitForChild("Normalaxe"):WaitForChild("BoolValue").Value)
	local success,response = pcall(function()
		ds:SetAsync(plr.UserId, datasave)
	end)

	if success then
		print("succesfully saved data of " .. plr.Name)
	else
		warn(response)
	end
end)

How so? We need more context to help? Possibly some logs?

1 Like

when i rejoinm ot kist replaces the data with the preset ones.

1 Like

Console logs please! Needed for debugging.

1 Like

16:40:35.126 Replacing no data with new data. - Server - Axes:22

1 Like

Does it say successfully saved in logs?

1 Like

it did not save


1 Like

wait it asaid data saved but when i load it it did not save

print success and response and see what happens,

for some reason I can not print them


game.Players.PlayerRemoving:Connect(function(plr)
	local datasave = {}
	table.insert(datasave, plr:WaitForChild("Homemadeaxe"):WaitForChild("BoolValue").Value)
	table.insert(datasave, plr:WaitForChild("Normalaxe"):WaitForChild("BoolValue").Value)
	local success,response = pcall(function()
		ds:SetAsync(plr.UserId, datasave)
	end)
	
	print(success)
	print(response)
	
	if success then
		print("succesfully saved data of " .. plr.Name)
	else
		warn(response)
	end
end)
local success, err = nil
		local attempt = 1

		repeat 
			success, err = pcall(function()
				ds:SetAsync(plr.UserId, datasave)
			end)
			attempt += 1
		until success or attempt == 5
		if success then
			print("Data saved")
		else
			warn(err)
		end

try this code

it did not work just to check is this the code?

game.Players.PlayerRemoving:Connect(function(plr)
	local datasave = {}
	table.insert(datasave, plr:WaitForChild("Homemadeaxe"):WaitForChild("BoolValue").Value)
	table.insert(datasave, plr:WaitForChild("Normalaxe"):WaitForChild("BoolValue").Value)
	local success, err = nil
	local attempt = 1

	repeat 
		success, err = pcall(function()
			ds:SetAsync(plr.UserId, datasave)
		end)
		attempt += 1
	until success or attempt == 5
	if success then
		print("Data saved")
	else
		warn(err)
	end
	print(success)
	
	if success then
		print("succesfully saved data of " .. plr.Name)
	else return
	end
end)

Yes, is studio access to apis on by chance?

yes it is, i have it for other datasaves

Hmm, ood. I’m stumped. Are you sure the values for the axes are created when they join?

dont they make them at the top of the script?

Ah, theres your problem, your not looking in the axes folder when using WaitForChild!

how would i revize it then???

do

table.insert(datasave, plr:WaitForChild("axes"):WaitForChild("Homemadeaxe"):WaitForChild("BoolValue").Value)
	table.insert(datasave, plr:WaitForChild("axes"):WaitForChild("Normalaxe"):WaitForChild("BoolValue").Value)

what did you change???You used waitforchild to?