Roblox age (days) limit before playing any games

Hello,

I would like to make the script counting down for days left.

Here is the script I made.

function OnEntered(Player)
	if Player.AccountAge < 30 then
		Player:Kick("Hello, sorry your account is too young due to security reasons you must wait 30 days before you can play.")
	end
end

game.Players.PlayerAdded:connect(OnEntered)print("Hello world!")

And I don’t know how much days do you recommend for them to play games to avoid leaking, etc. Is 30 days enough?

3 Likes

Uh, no. Hold on.
Instead of saying you must wait 30 days before you can play, calculate the number of days left by:

function OnEntered(Player)
	if Player.AccountAge < 30 then
		local amount_left = tonumber(30 - Player.AccountAge)
		Player:Kick("Hello, sorry your account is too young due to security reasons you must wait " .. amount_left .. " days before you can play.")
	end
end

scroll to the right :arrow_upper_right:

Yes, 30 days is enough.

7 Likes

Thank you, marked as solution.

2 Likes

What exactly does making players wait until their account is 30 days old do? Telling them they have to wait means they will probably give a dislike and never come back. Just wondering because I’ve seen a lot of people do this but I never understood why.

1 Like

Having a system that prevents the player from playing your game until his account is 30 days old is really a lot, 10 days is enough. People usually do that to try and prevent exploiters that use alts and scam bots.

Oh okay, anyways the script isn’t working. I tried putting 100 days and it didn’t kick me, it was for testing but the script doesn’t seems to be working and I’m 95 days then it should’ve kicked me to make sure if were working but nope.

function OnEntered(Player)
	if Player.AccountAge < 10 then
		local amount_left = tonumber(10 - Player.AccountAge)
		Player:Kick("Hello, sorry your account is too young due to security reasons you must wait " .. amount_left .. " days before you can play.")
	end
end

If that’s your entire code and nothing was outputted in the console, then you forgot to carry over the PlayerAdded connection. Typically why you shouldn’t just copy and paste things from this category but make sure that you’ve fully written out the missing parts of code where needed.

OH!! Lol, I forgot to do that heheh!!

Yes, as in

local Players = game:GetService("Players")
 
Players.PlayerAdded:Connect(OnEntered)`

Just add this^ to the top of the script, or use this:

local Players = game:GetService("Players")
 
Players.PlayerAdded:Connect(function(Player)
	if Player.AccountAge < 30 then
		local amount_left = tonumber(30 - Player.AccountAge)
		Player:Kick("Hello, sorry your account is too young due to security reasons you must wait " .. amount_left .. " days before you can play.")
	end
end)

Okay, I can do that and testing. :slight_smile:

While Aeventy’s solution would work, you can create a function and just pass in the arguments for the required account age.

local Players = game:GetService("Players")

local function checkAccountAge(player, ageRequirement, reason)
    assert(typeof(ageRequirement) == "number", "Number expected, got " ..tostring(ageRequirement))
    assert(typeof(reason) ==  "string", "String expected, got " .. tostring(reason))
    assert(player:IsA("Instance", "Instance expected, got " ..tostring(player))

    if player.AccountAge >= ageRequirement then
          return true
    else
         player:Kick(reason)
    end
end

Players.PlayerAdded:Connect(function(player)
     if player:IsDescendantOf(Players) then
        checkAccountAge(player, 30, "Your account age needs to be 30 days old")
    end
end)

Don’t just wrap the function into PlayerAdded because there may be other things you want to do inside that event. Though you can do that in the function, I wouldn’t really recommend doing since that function is made for another purpose. In order to main a clean and efficient code.

You don’t need to subtract the account age by the number of days, just use the >= operator.

The above code is much efficient than your current one.

I don’t see a reason for you to convert amount_Left into a number since subtracting numbers will return the subtracted answer in numbers.

it was missing this: )

on the next line assert(player:IsA("Instance", "Instance expected, got " ..tostring(player))

assert(player:IsA("Instance", "Instance expected, got " ..tostring(player))
	
)
	if player.AccountAge >= ageRequirement then