This tutorial will include the use of a ModuleScript
- In this first part you will need to insert a normal script into the ServerScriptService then inside that you will need a ModuleScript. (Name them anything but make sure to call them by that Name)
ModuleScript:
- Inside the ModuleScript, name the Module (The part that says BannedUsers. Do this for return) then separate the Curly Brackett like shown below:
--- In this ModuleScript should only require the Players userId and The reason for the ban
local BannedUsers = {
}
return BannedUsers
- Then inside the Curly Brackets type the code below: (Read the comments that in the code to understand the use)
--- In this ModuleScript should only require the Players userId and The reason for the ban
local BannedUsers = {
["User 1"] = {
["User"] = "USERID HERE", --- The Players UserId
["Reason"] = "REASON HERE" --- The reason for the ban
}
}
return BannedUsers
Script:
- Inside the script type this code below:
local BannedUsers = require(script.ConfigUsers) -- To get the info for the ban
With the purpose of the ModuleScript it makes it easier for you to access the Names and Reasons for their ban without taking too much room up in this Script.
- Before coding the rest you need to make a function for when the player joins the game.
local BannedUsers = require(script.ConfigUsers) -- To get the info for the ban
game.Players.PlayerAdded:Connect(function(Player)
end)
- In this step we are using Loops to access the listed player. (See step 2 to understand the next part)
local BannedUsers = require(script.ConfigUsers) -- To get the info for the ban
game.Players.PlayerAdded:Connect(function(Player)
for _, BannedPlayer in pairs(BannedUsers) do -- Getting the Player and the Reason for their ban
end)
- Inside the loop should be the code that kicks the player for being banned from the game.
local BannedUsers = require(script.ConfigUsers) -- To get the info for the ban
game.Players.PlayerAdded:Connect(function(Player)
for _, BannedPlayer in pairs(BannedUsers) do -- Getting the Player and their Reason for the ban
task.wait()
Player:Kick(BannedPlayer.User .."(".. Player.Name ..") Reason for ban: " ..BannedPlayer.Reason) -- Kicks the player for being banned
end
end)
BannedPlayer.User
- This gets the userId that was mention in step 2.
BannedPlayer.Reason
- This gets the Reason for the players ban mention in step 2.
The line:
Player:Kick(BannedPlayer.User .."(".. Player.Name ..") Reason for ban: " ..BannedPlayer.Reason) -- Kicks the player for being banned
Inside Kick()
can be option for what you say when the player is kicked.
Module Script
Final Code:
--In this ModuleScript should only require the Players userId and The reason for the ban
local BannedUsers = {
["User 1"] = {
["User"] = "USERID HERE", --- The Players UserId
["Reason"] = "REASON HERE" --- The reason for the ban
}
}
return BannedUsers
Script
Final Code:
local BannedUsers = require(script.ConfigUsers) -- To get the info for the ban
game.Players.PlayerAdded:Connect(function(Player)
for _, BannedPlayer in pairs(BannedUsers) do -- Getting the Player and their Reason for the ban
task.wait()
Player:Kick(BannedPlayer.User .."(".. Player.Name ..") Reason for ban: " ..BannedPlayer.Reason) -- Kicks the player for being banned
end
end)
If you want to add more users then follow this example:
--In this ModuleScript should only require the Players userId and The reason for the ban
local BannedUsers = {
["User 1"] = {
["User"] = "USERID HERE", --- The Players UserId
["Reason"] = "REASON HERE" --- The reason for the ban
},
["User 2"] = {
["User"] = "USERID HERE", --- The Players UserId
["Reason"] = "REASON HERE" --- The reason for the ban
}
}
return BannedUsers
If you want to learn, Don’t copy and paste