I'm having a problem at datastoring the boolvalue in my game

  1. What do you want to achieve? I wanted to save the value of the boolvalue in the player folder but I’ve found a big problem that my brain couldn’t solve.

  2. What is the issue? I am very new to datastoring coding, and right now I’m trying to saving alots of item boolvalue. after I’ve coded the script, it’s going well BUT when i turned one of the boolvalue to True and leave and rejoin. It’s somehow make all the other value goes True too. and when I tried to change it back by changing the datastore, all the value to false again. and leave and rejoin the game again. It’s still all the value are True. Please help I’ve been suffering this problem for 5 hours+ now (Sorry for my bad english)

  3. What solutions have you tried so far? Tried the dumbest ways possible that my brain could think of to fix this problem but it doesn’t work

---------This is Server Script In ServerScriptService-------------


local SWD = DSS:GetDataStore("DATA1")
local GVC = DSS:GetDataStore("DATA2")
local LSR = DSS:GetDataStore("DATA3")
local SPC = DSS:GetDataStore("DATA4")

game.Players.PlayerAdded:Connect(function(plr)
	print("Loaded")
	SWD:GetAsync(plr.UserId)
	GVC:GetAsync(plr.UserId)
	LSR:GetAsync(plr.UserId)
	SPC:GetAsync(plr.UserId)
	
	plr:WaitForChild("OwnedItems"):FindFirstChild("Sword").Value = SWD or false
	plr:WaitForChild("OwnedItems"):FindFirstChild("Gravity Coil").Value = GVC or false
	plr:WaitForChild("OwnedItems"):FindFirstChild("Laser Gun").Value = LSR or false
	plr:WaitForChild("OwnedItems"):FindFirstChild("Speed Coil").Value = SPC or false
	
	print(SWD)
	print(GVC)
	print(LSR)
	print(SPC)
end)


game.Players.PlayerRemoving:Connect(function(plr)
	print("saved")
	local OIT = plr:WaitForChild("OwnedItems")
	
	local SWD_VALUE = OIT:FindFirstChild("Sword").Value
	local GVC_VALUE = OIT:FindFirstChild("Gravity Coil").Value
	local LSR_VALUE = OIT:FindFirstChild("Laser Gun").Value
	local SPC_VALUE = OIT:FindFirstChild("Speed Coil").Value
	
	print(SWD_VALUE)
	print(GVC_VALUE)
	print(LSR_VALUE)
	print(SPC_VALUE)
	SWD:SetAsync(plr.UserId, SWD_VALUE)
	GVC:SetAsync(plr.UserId, GVC_VALUE)
	LSR:SetAsync(plr.UserId, LSR_VALUE)
	SPC:SetAsync(plr.UserId, SPC_VALUE)
end)

image_2022-04-07_020955197

Yes I know the code looks dumb, but I’m new to this topic. Please help!

First things first, why are you using so many data stores, instead of making new keys in just 1, second off

Here you are checking if SWD exists not if it’s equal to true, because the SWD variable references the data store itself not the value stored in it.

Try changing that to

local SWDBool = swd:GetAsync(plr.UserId)

And set the value of the sword book to SWDBool

The method “:GetAsync()” returns the value that is being requested from a DatatStore, you must store this value in a variable in order to use it. The reason why you always get true is because you are trying to store the DataStore reference which is considered true (only false and nil are considered false).

game.Players.PlayerAdded:Connect(function(plr)
	print("Loaded")
	local SWD_VALUE = SWD:GetAsync(plr.UserId)
	local GVC_VALUE = GVC:GetAsync(plr.UserId)
	local LSR_VALUE = LSR:GetAsync(plr.UserId)
	local SPC_VALUE = SPC:GetAsync(plr.UserId)

	plr:WaitForChild("OwnedItems"):FindFirstChild("Sword").Value = SWD_VALUE or false
	plr:WaitForChild("OwnedItems"):FindFirstChild("Gravity Coil").Value = GVC_VALUE or false
	plr:WaitForChild("OwnedItems"):FindFirstChild("Laser Gun").Value = LSR_VALUE or false
	plr:WaitForChild("OwnedItems"):FindFirstChild("Speed Coil").Value = SPC_VALUE or false

	print(SWD_VALUE)
	print(GVC_VALUE)
	print(LSR_VALUE)
	print(SPC_VALUE)
end)

I will try your solution later and change from having many datastore to only 1 using the table