Trying to save a boolvalue in a datastore

Hello I am not the best at datastores, but I tried saving a boolvalue and it didn’t work can somebody tell me how to fix my code?

local DataStoreService = game:GetService("DataStoreService")

local DataStore = DataStoreService:GetDataStore("BannedDataStore")

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

local Testing = game.ReplicatedStorage.Testing

Testing.Value = DataStore:GetAsync(LocalPlayer.UserId) or false

if Testing.Value == true then

print("hi")

end

end)

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

local Testing = game.ReplicatedStorage.Banned

DataStore:SetAsync(LocalPlayer.UserId, Testing.Value)

end)
1 Like

you cant do datastores in a local script

1 Like

its not in a localscript… lol

1 Like
local DataStoreService = game:GetService("DataStoreService")

local DataStore = DataStoreService:GetDataStore("BannedDataStore")

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

local Testing = game.ReplicatedStorage.Banned

Testing.Value = DataStore:GetAsync(Player.UserId)

if Testing.Value == true then
print("hi")
end

end)

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

local Testing = game.ReplicatedStorage.Banned

DataStore:SetAsync(Player.UserId, Testing.Value)

end)

try this(serverscript in serverscriptservice)

1 Like

didnt save the value, also

local Testing = game.ReplicatedStorage.Banned
``` forgot to change that banned to testing my bad lol
1 Like

try again with some edits i made

1 Like

An example of how to make a successful ban datastore would be to first use a game.Players.PlayerAdded function. In that function, you would basically make a BoolValue which would get parented to the player. This value will then be set to either True or False, which can be checked by doing something like local banval = DataStore:GetAsync(Player.UserId) or false. Then, if banval is equal to false, you would set the BoolValue to false with BoolValue.Value = false. However, if banval gets returned as not false, you can then kick the player by doing if banval then Player:Kick("Banned.") end.

Note: This isn’t supposed to save. If you want to save it, please just reply to this.

1 Like

Yeah I would love it to save! I am just not the best at datastores so your help would be appreciated!

1 Like

Alright! Let me just write it rq.

1 Like

This should do it.

local DataStoreService = game:GetService("DataStoreService");
local DataStore = DataStoreService:GetDataStore("BannedDataStore");

game.Players.PlayerAdded:Connect(function(player)
local boolval = Instance.new("BoolValue", player)

boolval.Value = DataStore:GetAsync(player.UserId) or false

if boolval.Value == true then
player:Kick("Banned.")
end

end)

game.Players.PlayerRemoving:Connect(function(player)
DataStore:SetAsync(player.UserId, player:FindFirstChild("BoolValue").Value)
end)
1 Like

Letme go test this one minute sorry

1 Like

A note: this isn’t going to check when the value is changed, so if you change it to True, the script isn’t going to detect it until the player leaves and joins again.

1 Like

Oh yeah ik that, one more minute

1 Like

Yea it didn’t work here I have no idea why not

Can you show the output? (A screenshot/file)

Due to security reasons, I won’t be installing that file. I only want an image of the output.

When I printed working 1 and 2 they printed but working 3 never printed

Do you have studio API services enabled? If not, its probably the reason why it’s not working.

Yes its enabled, does it have something to do when u said "FindFirstChild(“BoolValue”) it errored and said boolvalue was nil so I changed it it to findfirstchild(“Value”)

If you’re going to do findfirstchild("Value"), its going to error. This is because you’re looking for a nil object called Value which isn’t the name of the BoolValue inside of player. The name of the BoolValue is simply BoolValue. And findfirstchild is case sensitive, so it must be FindFirstChild. When in-game, can you try looking for BoolValue in the Players section under your player? If it’s not there, let me know.