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

BoolValue Datastore Error. (?)

Asked by 6 years ago

At first the the BoolValue's value is false and without changing its property it changes to true.

game.Players.PlayerAdded:connect(function(player)

local Folder = Instance.new("Folder",player)
Folder.Name = "BoolValues"

local bool = Instance.new("BoolValue",player.BoolValues)
    bool.Value = false
    bool.Name = "BoolTest"
local ds = game:GetService("DataStoreService"):GetDataStore("user"..player.userId)
local DataLoaded = ds:GetAsync("Test")

if DataLoaded == nil then
    DataLoaded = ds:SetAsync('Test',true)
end

    bool.Value = DataLoaded

end)
1
You do not get a data store per user, you create a key per user. User#5423 17 — 6y
1
Also note that SetAsync does not pass back any value. User#5423 17 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

Read kingdom5 comments first before reading this answer. You need to create a key per user, not a datastore per user. Thats too much. Example:

local DataStore = game:GetService("DataStoreService")

local ds = DataStore:GetDataStore("BoolValueSaves") --we are creating a datastore, and inside the datastore we create a key, which is basically a folder holding each players data.

game.Players.PlayerAdded:Connect(function(player)

local leader = Instance.new("Folder",player)
leader.Name = "BoolValues"

local bs = Instance.new("BoolValue",leader)
bs.Name = "BoolTest"

bs.Value = ds:GetAsync(player.UserId) or false --when the player joins, it searches the datastore for the player's key. if nothing was found, the value is set to false until the value is changed. when it's changed, it gets saved.

ds:SetAsync(player.UserId, bs.Value) --this is how you do it

bs.Changed:Connect(function() --when the value is changed,

ds:SetAsync(player.UserId, bs.Value) --update the value

end)

game.Players.PlayerRemoving:Connect(function(player)

ds:SetAsync(player.UserId, player.BoolValues.BoolTest.Value) --save the value when the player leaves.

end)

Hopefully I explained this good enough. If this helped PLEASE accept my answer!

0
Thanks man! :D SamthekidRSsl 58 — 6y
0
But what about Fe SamthekidRSsl 58 — 6y
0
It will work with FE. This just needs to be in a normal script in the serverscriptservice. PyccknnXakep 1225 — 6y
Ad

Answer this question