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

DataStore: How would I update a BoolValue saved in datastore?

Here is the script for creating the datastore value:

game.Players.PlayerAdded:connect(function(player)
local BV = Instance.new("BoolValue",player)
BV.Value = false
BV.Name = "Code1Redeemed"
local ds = game:GetService("DataStoreService"):GetDataStore("user"..player.userId)
ds:SetAsync("Code1", BV.Value)
end)

Now, I'm trying to update the value when a player clicks a button:

script.Parent.MouseButton1Down:connect(function()
local ds = game:GetService("DataStoreService"):GetDataStore("user"..player.userId)
local DataLoaded = ds:GetAsync("Code1")
ds:IncrementAsync("Code1", true)
print("Code1 sent to true")
end)

Unfortunately, It isn't working. I'm pretty sure I did it right, but I'm not sure. Any help appreciated.

1 answer

✓ Accepted answer

Instead of using IncrementAsync, you should be using SetAsync:

script.Parent.MouseButton1Down:connect(function()
	local ds = game:GetService("DataStoreService"):GetDataStore("user"..player.userId)
	local DataLoaded = ds:GetAsync("Code1")
	ds:SetAsync("Code1", true)
	print("Code1 sent to true")
end)

For more info:

http://wiki.roblox.com/index.php?title=API:Class/GlobalDataStore/SetAsync

2 comments

0

Thank you!

0

No problem.

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