Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Value gets reverted after changing it what can I do?

local DSS = game:GetService("DataStoreService")
local DS = DSS:GetDataStore("ETSING BOY")
local ValuesToCreate = {TermsOfUse = {Name = "TermsOfUse", className = "BoolValue", Value = false}}

game.Players.PlayerAdded:Connect(function(Player)
	local Folder = Instance.new("Folder", Player)
	Folder.Name = "PlayerData"
	
	for i,v in pairs(ValuesToCreate)do
		local Val = Instance.new(v.className, Folder)
		Val.Name = v.Name
	end
	
	local SavedData
	local success, errormsg = pcall(function()
		SavedData = DS:GetAsync(Player.UserId)
	end)
	if success and SavedData ~= nil then
		print("SAVED DATA OF PLAYER "..Player.Name..": "..game:GetService("HttpService"):JSONEncode(SavedData))
		for i,v in pairs(SavedData)do
			local FindVal = Folder:FindFirstChild(v.Name)
			if FindVal and FindVal.className == v.className then
				FindVal.Value = v.Value
			end
		end
	elseif success and SavedData == nil then
		for i,v in pairs(ValuesToCreate)do
			local FindVal = Folder:FindFirstChild(v.Name)
			if FindVal and FindVal.className == v.className then
				FindVal.Value = v.Value
			end
		end
	elseif not success then
		warn("Error while trying to get saved data of player "..Player.Name..": "..errormsg)
	end
end)

game.Players.PlayerRemoving:Connect(function(Player)
	if not game:GetService("RunService"):IsStudio() then
		local Folder = Player:WaitForChild("PlayerData")
		local SaveData = {}
		for i,v in pairs(Folder:GetChildren())do
			SaveData[v.Name] = {Name = v.Name, className = v.className, Value = v.Value}
		end
		print("SAVING DATA OF PLAYER "..Player.Name..": "..game:GetService("HttpService"):JSONEncode(SaveData))
		local success, errormsg = pcall(function()
			DS:SetAsync(Player.UserId, SaveData)
		end)
		if not success then
			warn("Couldn't save data of player "..Player.Name..": "..errormsg)
		end
	end
end)

game:BindToClose(function()
	for i, Player in pairs(game.Players:GetPlayers())do
		local Folder = Player:WaitForChild("PlayerData")
		local SaveData = {}
		for i,v in pairs(Folder:GetChildren())do
			SaveData[v.Name] = {Name = v.Name, className = v.className, Value = v.Value}
		end
		print("SAVING DATA OF PLAYER "..Player.Name..": "..game:GetService("HttpService"):JSONEncode(SaveData))
		local success, errormsg = pcall(function()
			DS:SetAsync(Player.UserId, SaveData)
		end)
		if not success then
			warn("Couldn't save data of player "..Player.Name..": "..errormsg)
		end
	end
end)
	

So everytime I change "TermsOfUse" to true I make the datastore script print out the whole table it's going to save and there it says that "TermsOfUse" is false and the datastore saves it as false aswell.

what can I do about it??

17 comments

0

wait where is the problem?

0

The output gives no error but I have a bool value which I want to save by a datastore system and everytime I change the bool value to true the datastore saves it as false

0

so; in other words, u mean that when u set it to true, it reverts to false immediately after?

0

so u save it as false right? not that it loads as a false?

0

i can only think of something tht keeps resetting it as false

0

or that the script failed to set it to true?

0

yes it saves it as false and it loads it as false aswell because it was saved as false although i changed it to true

0

and i change the value by myself using the properties tab or using the console in studio

0

ok

0

then either ur hand is broken, or ur script to save it is

0

no offense

0

xd alright thanks for your help

0

OH CRAP

0

i remember

0

wait lemme type it out as answer

0

i need rep ;-;

0

how to rep im new

1 answer

✓ Accepted answer

the datastore does not save anything u change in the studio; only in the game itself. So to really test out wether ur datastore saves, u have to test it in ur actual game

3 comments

0

good game

0

ok thanks im gonna try it out right away

0

lol

This discussion is preserved as it was. New answers, comments, and votes are closed.