Datasave with bool values not saving

Datasave with bool values in not saving. Is it impossible to save them? Here is the code that saves them Ill reply with the code that loads them.

–Made by Its4Realzies
local data = game:GetService(‘DataStoreService’)

function savePlayerData(player)

local saveData = data:GetDataStore('saveData', player.UserId)

saveData:setAsync('Points', player.leaderstats.Points.Value)

local playerFolder = workspace:FindFirstChild(player.UserId)
--Items
saveData:setAsync('OwnsSwuvleIt', playerFolder.It1.Value)
saveData:setAsync('OwnsSniperIt', playerFolder.It2.Value)
saveData:setAsync('OwnsMedkitIt', playerFolder.It3.Value)
saveData:setAsync('OwnsDynamiteIt', playerFolder.It4.Value)

saveData:setAsync('OwnsSwuvleUp', playerFolder.Up5.Value)
saveData:setAsync('OwnsSniperUp', playerFolder.Up6.Value)
saveData:setAsync('OwnsMedkitUp', playerFolder.Up7.Value)
saveData:setAsync('OwnsDynamiteUp', playerFolder.Up8.Value)

playerFolder:Destroy()

end

game.Players.PlayerRemoving:Connect(savePlayerData)

This is the code that loads save data

—Made by Its4Realzies
local data = game:GetService(‘DataStoreService’)

function newPlayer(player)

local saveData = data:GetDataStore('saveData', player.UserId)
local points = saveData:getAsync('Points')

local stats = Instance.new('Model', player)
stats.Name = 'leaderstats'

local pointStat = Instance.new("IntValue", stats)
pointStat.Name = 'Points'
pointStat.Value = points or 0

--Creates folder for values
local newItemFolder = Instance.new('Folder', workspace)
newItemFolder.Name = player.UserId

--SwuvleItem ID: 1
local ownsSwuvle1 = saveData:getAsync('OwnsSwuvleIt')
local ownsSwuvleItem = Instance.new('BoolValue', newItemFolder)
ownsSwuvleItem.Name = 'It1'
ownsSwuvleItem.Value = ownsSwuvle1 or false

--SniperItem ID: 2
local ownsSniper1 = saveData:getAsync('OwnsSniperIt')
local ownsSniperItem = Instance.new('BoolValue', newItemFolder)
ownsSniperItem.Name = 'It2'
ownsSniperItem.Value = ownsSniper1 or false

--MedkitItem ID: 3
local ownsMedkit1 = saveData:getAsync('OwnsMedkitIt')
local ownsMedkitItem = Instance.new('BoolValue', newItemFolder)
ownsMedkitItem.Name = 'It3'
ownsMedkitItem.Value = ownsMedkit1 or false

--DynamiteItem ID: 4
local ownsDynamite1 = saveData:getAsync('OwnsDynamiteIt')
local ownsDynamiteItem = Instance.new('BoolValue', newItemFolder)
ownsDynamiteItem.Name = 'It4'
ownsDynamiteItem.Value = ownsDynamite1 or false

--SwuvleUpgrade ID: 5
local ownsSwuvle2 = saveData:getAsync('OwnsSwuvleUp')
local ownsSwuvleUpgrade = Instance.new('BoolValue', newItemFolder)
ownsSwuvleUpgrade.Name = 'Up5'
ownsSwuvleUpgrade.Value = ownsSwuvle2 or false

--SniperUpgrade ID: 6
local ownsSniper2 = saveData:getAsync('OwnsSniperUp')
local ownsSniperUpgrade = Instance.new('BoolValue', newItemFolder)
ownsSniperUpgrade.Name = 'Up6'
ownsSniperUpgrade.Value = ownsSniper2 or false

--MedkitUpgrade ID: 7
local ownsMedkit2 = saveData:getAsync('OwnsMedkitUp')
local ownsMedkitUpgrade = Instance.new('BoolValue', newItemFolder)
ownsMedkitUpgrade.Name = 'Up7'
ownsMedkitUpgrade.Value = ownsMedkit2 or false

--DynamiteUpgrade ID: 8
local ownsDynamite2 = saveData:getAsync('OwnsDynamiteUp')
local ownsDynamiteUpgrade = Instance.new('BoolValue', newItemFolder)
ownsDynamiteUpgrade.Name = 'Up8'
ownsDynamiteUpgrade.Value = ownsDynamite2 or false

--Gives teleport wand
if player.UserId == 228981555 or 500720167 or 266270712 then
	local tool = game.ReplicatedStorage:FindFirstChild("Teleport Staff")
	local toolClone = tool:clone()
	toolClone.Parent = player.Backpack
end

end

game.Players.PlayerAdded:Connect(newPlayer)

There is NO ERRORs but the loading without (or false) = nil

Woah woah. First of all, there is no second parameter for GetDatsStore. You put the player ID in the key, not in the datastore. I reccomend watching a tutorial, because it seems there might be more than a few things wrong here. A good tutorial is AlvinBlox’s tutorials.

When you load or save a bool value it will be string

as you can see “true” is different from true.

You need to do something like this:

function GetOrginalBool(Value)
     if Value == "true" then
         return true
     end
     if Value == "false" then
         return false
     end
end

@iamtryingtofindname is absolutely correct here. (Although I don’t advice watching a video, they are all outdated)

I recommend revising the basics of Datastores. from the API

1 Like

Also your data store calls need to be wrapped in a pcall, and you should not be making calls for each item. Save it all in a table. Follow a tutorial or use DataStore2 module.

But the point one works and I did the bool one exactly the same :confused:

It might work for one player, but what you are doing right now is you are saving everyone’s data to one key. Which means everyone shares the same player data. This is bad, each player should have their own key and player data.

I can assure you this works 100% on multiply in studio and in game.

It working or not working doesnt matter if everyones data is saved to one save.

Lets say I play the game, the data is saved.

Then you come along and it finds the data I saved.

You see the issue?

1 Like

I have used this code almost identical to this in other games it it works. I don’t want to argue with you. Thankyou for helping me solve the bool save problem!

Ill have to take your word for it then.

I had a look through and it looks like you are defining the player when getting the store itself which is bad news. (May work may not idk)

Below you can have a look at a rough function I made for saving data the correct way. You can also use GetAsync() in a similar way.

function SetData(Store,Player,Data)
	for i = 1,10 do
		local S, R = pcall(function()
			local NewStore = DataStoreService:GetDataStore(Store)
			NewStore:SetAsync(Player,Data)
		end)
		if S then
			print("Set Data")
			break
		else
			print("DSS Error:")
			print(R)
			wait(2)
		end
	end
end
1 Like

You did not understand what I said. You enter the UseId in the key. If you don’t listen to me now, you will find out when multiple people play the game. Please read this article for example on how to save player data properly. Currently, yours will not work for more than one person, and everyone’s data will be shared. Saving Data | Roblox Creator Documentation

You should be saving with the player’s UserId, as datastores do not accept instances.

Also there has to be a 6 second delay between write requests to the same key. Read more here: https://developer.roblox.com/en-us/articles/Datastore-Errors

Line 6 is using the players Id does it not??? M

No, assuming you enter the player instance as a parameter for “Player”. If the “Player” parameter is the UserId, then it’s fine.

Player is a variable here, meaning it is the User.Id if I put it in, as for the wait time ill have to change it, thanks.

(This is from a draft of my DSS3 script that does all kinds of wonders, e.g endless backups, infinite data capacity. Datastore networking (SubLinked Stores). I know what im doing but the wait time is subject to change)

You are going to use OrderedDataStores for backups?

Im sorry I do not understand what are you saying?

The stores names are numbers and put under the players save name as the store name. This means that its already in order and I can see how many saves they have and what not. It doesn’t require data overrides for any saving which means that I can backlog for years.

This means all I have to do is get the number of saves and get the last one, if that save is corrupted I just iterate through then backwards until I get a usable one.

Its all done with the bare basics of data saving, SetAsync() and GetAsync() :slight_smile: