So What im trying to achieve is a Server Ban System Using Tables
A Solution i have tried is Searching Tables on Developer Hub
the Code i Have is
local sBan = {
}
game.ReplicatedStorage.SBan.OnServerEvent:Connect(function(plrToBan, Reason)
table.insert(plrToBan)
game.Players.PlayerAdded:Connect(function(plr)
if plr.Name == table[1] then
plr:Kick("You Have been Banned in this Server for: "..Reason.."/n You Do Not Have to Appeal as this is not a game ban")
end
end)
end)
That’s not how you insert something into a table. You do it like this: table.insert(sBan, plrToBan)
You’re just comparing the name of the player against the first entry of the table. To look through the table for a name, do this: if table.find(sBan, plr.Name) then
Define the playerAdded Connection outside the onServerEventConnection
This would ban the player who fired the event, since the first parameter of onServerEvent is the client that fired the remote event.
local BannedPlayers = {'Player', 'Player2', 'Player3'}
game.Players.PlayerAdded:Connect(function(Player)
for i, BannedPlayer in pairs(BannedPlayers) do
if BannedPlayer == Player.Name then
Player:kick('You are banned from this game.')
end
end
end)
local sBan = {
}
game.ReplicatedStorage.SBan.OnServerEvent:Connect(function(plrToBan )
table.insert(sBan, plrToBan)
end)
game.Players.PlayerAdded:Connect(function(plr)
if table.find(sBan, plr.Name) then
plr:Kick("You Have Been Banned From this Server")
end
end)