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)
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)
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.
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)
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.
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.