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 6 years ago

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

Log in to vote
1
Answered by 6 years ago

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

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

Answer this question