Bool value saves in datastore, but refuses to load

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

im attempting to make saving settings, a few of witch are bool values.

  1. What is the issue? Include screenshots / videos if possible!
    for some reason, the value saves into the datastore properly, and you can even print it.
    but attempting to load it into said value, doesnt work, and prints 0 errors.
    image_2025-01-25_142449729

  2. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

ive tried doing the or method, no results
ive tried directly loading the value with GetAsync instead of using a variable
no results

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

	local Settings = script.Settings:Clone()
	Settings.Parent = player
	
	for i,v in pairs(Settings:GetChildren()) do
		local e = ds:GetAsync(player.UserId.."-"..v.Name)
		print(e)
		
		if e then
			v.Value = e
		end
		
		print(v.Name.."  ".. tostring(v.Value))
	end

whats going on here?

You’re going to kick yourself hahaha.

It’s because you’re doing this:

if e then
    v.Value = e
end

Doing that means you expect ‘e’ to be true, but because the value’s coming back as ‘false’, that check won’t pass. :slight_smile:

You can do this in a better way using pcall, essentially almost like a Roblox version of a try/catch, except you need to handle if there is an error, since the general error detection built into Roblox ignores any code within one.

Give this a whirl:

local Settings = script.Settings:Clone()
Settings.Parent = player
	
for i,v in pairs(Settings:GetChildren()) do
    local data = nil

    local success, err = pcall(function()
        data = ds:GetAsync(player.UserId.."-"..v.Name)
        print(data)
    end)
		
    if success then
        v.Value = data
    else
        warn(err)
    end
		
    print(v.Name.."  ".. tostring(v.Value))
end

oml, that explains alot then.
i was expecting for it to check if it exists, not if its true-

thanks for the amazing help!

No worries at all, glad I could help. :slight_smile: