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

BoolValue Datastore Error. (?)

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)

2 comments

1

You do not get a data store per user, you create a key per user.

1

Also note that SetAsync does not pass back any value.

1 answer

✓ Accepted answer

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!

4 comments

0

Thanks man! :D

0

But what about Fe

0

It will work with FE. This just needs to be in a normal script in the serverscriptservice.

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