How would I Ban a account under five months old and Ban accounts if they touch a part?
You’ll have to know their AccountAge, and 5 months is roughly estimated to 150 days.
Use the BasePart.Touched
event.
Is their a Ban function in player like Player:Kick()? and yes, I intentionally made it so it was 5 months, I don’t want any types of new players joining.
Unfortunately, there is not functions which bans a player a specific amount of time like Player:Ban()
, you will have to use data stores to compare their account age with the minimum account age your game allows.
players.PlayerAdded:Connect(function(player)
for _,v in pairs(bans) do
if v == player then
player:Kick()
end
end
if accountage <= minage then
player:Kick()
table.insert(bans, player)
DS:SetAsync("Bans", bans)
end
end)
This is the simplest way you could do that.
-- server script
game.Players.ChildAdded:Connect(function(player)
if player.AccountAge <150 then player:Kick("Your account has to be around 150 days old to play this game.") end
end)
What is the minage value?
The player could return in the span of 5 months if the really wanted to.
were talking about alts here also.
The minimum age, which would be 150.
I know, this just kicks them when they join and is under 5 months of age. Every day their account age gets updated so kicking them isn’t banning them. Once their account becomes 5 months old and they join the game again they can play without being kicked.
local part = script.Parent
local players = game:GetService("Players")
part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local character = hit.Parent
local player = players:GetPlayerFromCharacter(character)
if player then
player:Kick("Don't touch the part!")
end
end
end)
local players = game:GetService("Players")
players.PlayerAdded:Connect(function(player)
if player.AccountAge <= 150 then
player:Kick("Your account is under 150 days old!")
end
end)
Both are server scripts, the first goes into a part of which when touched the touching player should be kicked and the second goes into the ServerScriptService folder (if player too young then kick).
I wouldn’t personally reccommend banning people under 5 months old, as that’s just gonna pester new players away, if you really need to, then you can use account age.
local Players = game:GetService("Players")
local minimumAge = 150 -- 150 days/5 months
Players.PlayerAdded:Connect(function(player)
if player.AccountAge < minimumAge then
player:Kick("You need to be atleast " .. tostring(minimumAge) .. " days old to play!")
end
end)
I really don’t reccommend it but anyway
Here is the script for the touch part. Make sure you parent this script to the part!
local Datastore = game:GetService("DataStoreService"):GetDataStore("BansDataStore")
local Part = script.Parent
local Players = game:GetService("Players")
Players.PlayerAdded:connect(function(player)
local data
local success, err = pcall(function()
data = Datastore:GetAsync("Bans") or {}
end)
if success then
for i, v in pairs(data) do
if v == player.UserId then
player:Kick("You are banned!")
end
end
else
warn(err)
end
end)
Part.Touched:Connect(function(hit)
if hit.ParentFindFirstChild("Humanoid") then
local Character = hit.Parent
local player = Players:GetPlayerFromCharacter(Character)
if player then
local success, err = pcall(function()
Datastore:SetAsync("Bans", player.UserId)
end)
if success then
print(player.Name.."has been added to the ban table")
player:Kick("You have been banned by touching this part!")
else
warn(err)
end
end
end
end)
Script for restricting account age. Make sure to put this script in SSS (ServerScriptService)!
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
if player.AccountAge <= 150 then
player:Kick("Your account age must be 150 days old or older to join!")
end
end)
Banning an account under 5 months old means they can never access the game unless you edit their DataStore.
The OP never mentioned 5 years. It mentioned 5 months.
Oops, my bad, I had to type quickly.
That script basically just kicks the person if the account is under 5 months old, alts wouldn’t work.
To ban a player that has an account younger than 5 months, you can do what everyone said above.
But making a ban system is quite more complicated.
There is a really good post that shows how you can create a ban system using SQL database with a REST API.