Hello! I’m trying to make a ban system where you can insert a name into the table with a command, and it saves the table to data stores. I don’t know how to save the table correctly.
Code:
local bannedUserIds = {}
game.Players.PlayerAdded:Connect(function(player)
if table.find(bannedUserIds, player.UserId) then
player:Kick("Banned \n \nYour account has been banned from this experience for exploits, inappropriate drawings, or another reason. \n \nThis ban is permanent and cannot be appealed under any circumstance. \n \nThis ban was given by the moderators of this experience. Roblox, or Roblox Support cannot do anything in this circumstance.")
end
end)
I don’t recommend using a table, but instead doing it another way
When the command is used, just save their player Id into the datastore, and set to true, meaning they are banned.
local success, errormessage = pcall(function()
BanDataStore:SetAsync(TargetId, true)
end)
if success then
Target:Kick("Message")
end
Then when the player joins, retrieve the data and see if their player Id and value is true.
local DataStoreService = game:GetService("DataStoreService")
local BanDataStore = DataStoreService:GetDataStore("BanDataStore")
game.Players.PlayerAdded:Connect(function(player)
local playerId = player.UserId
local banned
local success, errormessage = pcall(function()
banned = BanDataStore:GetAsync(playerId)
end)
if banned == true then
player:Kick("Message")
end
end)
I suggest undertstanding how these types of things work because its pretty useful when saving important data. Note: That isn’t all the code, but the main thing you’d want to be doing, at least from what I’ve seen.
1 Like