Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 7 years ago

Here is the script for creating the datastore value:

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

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

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

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

1 answer

Log in to vote
1
Answered by 7 years ago

Instead of using IncrementAsync, you should be using SetAsync:

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

For more info:

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

0
Thank you! PyccknnXakep 1225 — 7y
0
No problem. BreadyToCrumble 121 — 7y
Ad

Answer this question