Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Saving list of banned users to a table?

so I'm having issues saving bans and such using a datastore I was wondering if anyone could help me I'm kinda stuck at the end

local DataStore = game:GetService("DataStoreService"):GetDataStore("BannedList")
local bans = {""}
local admins = {"admin"}

local victim
function tableContains(t, value)
    for _, v in pairs(t) do
        if v == value then 
            return true
        end
    end
    return false
end

function findPlayer(name)
    for _, player in ipairs(game.Players:GetPlayers()) do
        if player.Name:lower() == name:lower() then
            return player
        end
    end
end

game:GetService("Players").PlayerAdded:connect(function(player)
    player.Chatted:connect(function(msg)
if msg:sub(1, 4) == "ban/" and tableContains(admins, player.Name) then
	victim = findPlayer(msg:sub(5))
		if victim then
			end
		end
    end)
    

1 answer

Whenever you refer to a value with TableName[Value], that value in between the brackets is the index of the table. For instance, if I have a table of 4 values:

Table = {"A","B","C","D"}
print(Table[4]) -- Prints D

Instead of victim.Name, you have to use a number in that instance.

If you are just trying to insert a new value into the table, it's simpler than you think

table.insert(Table,victim.Name) -- You can also pass a 3rd argument if you want to insert it in a specific index of the table.

2 comments

0

I'm just trying to save a table here nothing special

0

Then why didn't you say that in the question? The more detailed your explanation, the more detailed your answer.

This discussion is preserved as it was. New answers, comments, and votes are closed.