Hello, so I’ve been scripting a ban and unban system. And I’ve been using a table called “manual” to store names of people who’ve been banned. Although there is the table, it’s still consider the table as nil. Can anyone help me with this?
It considers the table value as nil, although I’ve already created a variable and marked it as a table.
Here is the script
local AdminList = require(script.Parent.Settings.AdminList)
local CommandName = require(script.Parent.Settings.CommandName)
local Other = require(script.Parent.Settings.CommandName)
local DS = game:GetService("DataStoreService")
local Bans = DS:GetDataStore("Key2")
if Other.enabled == false then
script.Disabled = true
end
local manual = {}
game.Players.PlayerAdded:Connect(function(plr)
for i, v in pairs(AdminList.Adminlist) do
if v == plr.Name then
print("[HADES]: Welcome, administrator.")
end
end
local data
local success, err = pcall(function()
data = Bans:GetAsync("Key2")
end)
if success then
manual = data
print("[HADES]: Banlist has been updated.")
else
print("[HADES]: Banlist has failed to update.")
warn("[HADES]: " ..err)
end
for i, v in pairs(manual) do
if v == plr.Name then
plr:Kick("You are banned.")
end
end
plr.Chatted:Connect(function(msg)
local mes = msg:lower()
local splitted = mes:split(" ")
if splitted[1] == "!kick" then
print(msg)
for i, v in pairs(AdminList.Adminlist) do
if v == plr.Name then
local target = splitted[2]
for i, v in pairs(game.Players:GetPlayers()) do
for i = 1, v.Name do
if splitted[2] == string.sub(v.Name, 1, i) then
v:Kick("By admin.")
end
end
end
end
end
end
if splitted[1] == "!ban" then
for i, v in pairs(AdminList.Adminlist) do
if v == plr.Name then
local target = splitted[2]
for i, v in pairs(game.Players:GetPlayers()) do
for i = 1, v.Name do
if splitted[2] == string.sub(v.Name, 1, i) then
v:Kick("Banned from the game.")
table.insert(manual, #manual+1, tostring(v.Name))
local success, err = pcall(function()
Bans:SetAsync("Key2", manual)
end)
if success then
print("[HADES]: Ban registered.")
else
warn("[HADES]: Ban log failed.")
warn("[HADES]: " ..err)
end
for i, v in pairs(manual) do
print(v)
end
end
end
end
end
end
end
if splitted[1] == "!unban" then
for i, v in pairs(AdminList.Adminlist) do
if v == plr.Name then
local target = splitted[2]
for i, v in pairs(game.Players:GetPlayers()) do
for i = 1, v.Name do
if splitted[2] == string.sub(v.Name, 1, i) then
for index, val in pairs(manual) do
if val == v.Name then
table.remove(manual, index)
local success, err = pcall(function()
Bans:SetAsync("Key2", manual)
end)
if success then
print("[HADES]: Unban registered.")
else
warn("[HADES]: Unban failed.")
warn("[HADES]: " ..err)
end
end
end
end
end
end
end
end
end
end)
end)```