I am lost at the point of adding the player to the table. I am new with tables and have tried many things but nothing seems to have worked. Here is the snippet of the ban script (Its meant for a module script)
local Homeblox = {} local B = {} --Table I want to add players too function Homeblox.Ban(plr) game.Players[plr]:Kick("Homeblox | You have been banned from the server") table.insert(B, plr) -- I am confused on adding and inserting into tables game.Players.PlayerAdded:Connect(function(plr) if plr.Name == B then -- I dont know how to check for it plr:Kick("Homeblox | You have been banned from the server") end end) end --Sample of the function that would be ran with player name Homeblox.Ban("CALEBBEN3") return Homeblox
Any help would be appreciated, thanks :)
table.insert(B, plr) -- I am confused on adding and inserting into tables
The arguments for table.insert are table.insert( TableToInsertTo , Position , Value )
therefore yours wouldn't work, and since you're trying to add a string ( player's name? ) then it would be optimal to use a dictionary (you dont necessarily have to) , so instead, you should be doing B[plr]
but if you intend on using table.Insert, then it would be
table.Insert(B, 1, plr)
if plr.Name == B then -- I dont know how to check for it
You can check through the table by looping through it, like so
for i,v in pairs( B ) do if v == plr then -- or plr.Name plr:Kick() end end
to check a string against a table, you just need to loop through every element and check if the players name is equal to any of them.
game.Players.PlayerAdded:Connect(function(plr) for i, Name in pairs(B) then -- loop through every element if plr.Name == Name then plr:Kick("Homeblox | You have been banned from the server") break; -- dont need to continue since we found them end end end)