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

How can you save the value of any Value?

Alright so it may sound a bit repetitive, but try to understand. Specifically a boolean value, I need to save the value of the Boolean Value itself. Since I know you cant save the Boolean Value itself, I know you can save the value of it. Anyway, I tried to do it here, but It doesn't work. Can anyone please explain why?

So, first I used SetAsync() which didn't work, so then I try UpdatedAsync() which doesn't work either. All I need to do is just save the value of the BoolValue so which one should I use? P.S. Everyone receives a bool value inside the folder named PlayerValues that is cloned to every player.

Every time I join the game it says the value is saved, but when I rejoin it says that it is false, turns true, and saves it again.

game.Players.PlayerAdded:Connect(function(player)
	local ValueDataStore = game:GetService("DataStoreService"):GetDataStore("SaveValueDataStore")
	local ValueNeedSaving = player:WaitForChild("PlayerValues",1):FindFirstChild("ValueNeedSaving")
	local valuekey = 0
	if ValueNeedSaving.Value == true then
		print("This value is already true!")
	else
		--SAVE TABLE PART--
		ValueNeedSaving.Value = true
		ValueDataStore:UpdateAsync(AlreadyGivenValue.Value, function()
			return AlreadyGivenValue.Value or 0
		end)
		print("The Value was saved and it will stay true!")
end)

3 comments

0

Could you make your question a bit more clear? Do you want to save the BoolValue object itself or BoolValue.Value?

0

The BoolValue.Value

0

You didn't load it, use SetAsync("player",table_or_values)

1 answer

✓ Accepted answer

Alright so here is an example for the DataStore saving a Boolean Value Should be placed in a Script in the ServerScriptService

local DSS = game:GetService("DataStoreService")
local Storage = DSS:GetDataStore("GUI")

game.Players.PlayerAdded:Connect(function(player)
	local bool = Instance.new("BoolValue", player)
	bool.Name = "GuiCheck"
	
	player.GuiCheck.Value = Storage:GetAsync(player.UserId) or false
	Storage:SetAsync(player.UserId, player.GuiCheck.Value)
	print("Sync")
end)

game.Players.PlayerRemoving:Connect(function(player)
	
	print("Saving Data")
	Storage:SetAsync(player.UserId, player.GuiCheck.Value)
	print("Data Saved")
end)

The first function creates the bool then changes its value to match the saved value The second function saves the value You will need a function to alter this value to true in order to change its parameters, so make it so that if the "GuiCheck" is false then the Gui appears and the GuiCheck becomes true.

3 comments

0

Thanks I'll test it then accept once I get it working!

0

Yep, oh and with the function to test if the bool is a certain value, you will need to add a wait(#) parameter so that it has time to load the value (you may want it to also be attached to the player's connection for smoothness)

0

right right

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