I need help with my ban system

I have no idea why, but this script is refusing to working. With my current setup, I’m inserting a value into a folder within the player object and it is being saved with datastore. After you ban them with the command, they are kicked and the value is set to true, but using a test account it won’t kick them when the rejoin after a ban. Any ideas?

wait(0.1)

game.Players.PlayerAdded:Connect(function(player)
	if player.stats.banned.Value == true then
		player:Kick("Banned by admin")
	end
end)

I

You could just store banned UserId’s in a data store instead:
(And when a player is banned, insert their UserId into the data store and set it to true)

local DataStoreService = game:GetService("DataStoreService")
local BanStore = DataStoreService:GetDataStore("Ban")


game.Players.PlayerAdded:Connect(function(player)
    local isPlayerBanned = BanStore:GetAsync(player.UserId)

    if isPlayerBanned then
        player:Kick("You are banned")
    end
end)

So when I ban them with the command I would call the datastore and insert their user Id inside the table?

Yes, like this for example

local DataStoreService = game:GetService("DataStoreService")
local BanStore = DataStoreService:GetDataStore("Ban")

local function ban(player)
    BanStore:SetAsync(player.UserId, true)
end

When you set the async, what is the use of the “true” at the end of the statement (I just want to know more for future refrence)

I don’t know if you know about data stores, but with the SetAsync function that sets a value to a key. (It works the same way in a dictionary or a table, for example in the table {[1] = "Hello"} 1 would be the key and Hello would be the value.) In this case, the key is the player’s UserId and the value is true. So whenever we look up the player’s UserId we will get true if they are banned or nil if they aren’t