Temporary Ban For 100 Rejoins

My goal is to make a temporary 1 day ban when the player gets kicked out of the game 100 times, but the problem is I don’t know how to make the temporary ban

I’ve tried solutions on the developer hub, but the ban wasn’t placed. Here is the link to the solution I used:

	if game.Players.plr.leaderstats.Kicks < 99 then
        -- this is where the temporary ban should be placed
	end
3 Likes

Using the new BanAsync feature, it’s quite simple to do a temporary ban:

local Player = ...

game.Players:BanAsync({
	UserIds = {Player.UserId},
	Duration = 3600 * 24, -- 1 day
	DisplayReason = "set this",
	PrivateReason = "set this",
})
3 Likes

Alright, I’m checking if this works. I’ll update you soon

2 Likes

Don’t forget to reset the kicks datastore before banning the player.

2 Likes

Unfortunately, this didn’t work. It’s because of the control statement, because “argument 1 is missing”, and skips over to the normal ending

if game.Players:FindFirstChild(Player).leaderstats.Kicks == 100 then
		game.Players:BanAsync({
			UserIds = {Player.UserId},
			Duration = 3600 * 24, -- 1 day
			DisplayReason = "Just take a break.",
			PrivateReason = "",
		})
		game:GetService("BadgeService"):AwardBadge(plr.UserId, --[insert badge id])

what is Player in game.Players:FindFirstChild(Player) ? Also unnecessary use of FindFirstChild use game.Players[Player]

You are passing a instance to the FindFirstChild, that receives a string, try replacing it with game.Players:FindFirstChild(Player.Name). and comparing Player.leaderstats.Kicks which is an instance with 100, add a .Value after Kicks and before the ==.
It also looks like you are passing the wrong thing to AwardBadge in the last line, try it with Player instead of plr.
Or just try with this piece of code:

if game.Players:FindFirstChild(Player.Name).leaderstats.Kicks.Value == 100 then
		game.Players:BanAsync({
			UserIds = {Player.UserId},
			Duration = 3600 * 24, -- 1 day
			DisplayReason = "Just take a break.",
			PrivateReason = "",
		})
		game:GetService("BadgeService"):AwardBadge(Player.UserId, --[[insert badge id]])
end
game.Players.PlayerAdded:Connect(function(plr)
    local Player = plr.Name
-- the rest of my code is here, but i didn't add it
    if game.Players:FindFirstChild(Player).leaderstats.Kicks == 100 then
		game.Players:BanAsync({
			UserIds = {Player.UserId},
			Duration = 3600 * 24, -- 1 day
			DisplayReason = "Just take a break.",
			PrivateReason = "set this",
		})
		game:GetService("BadgeService"):AwardBadge(plr.UserId, 1276017689712360)
	else

plr.Name.UserId doesn’t really make sense does it…
instead of Player.UserId do plr.UserId
Also like @TheMegaPeguinPro said before a intvalue/numbervalue (leaderstats.Kicks) will never be 100, don’t forget to add .Value after it

“Argument 1 missing or nil - Server - Script:23”
Script:23 is if game.Players:FindFirstChild(Player.Name).leaderstats.Kicks.Value == 100 then
the badge script also works when i did it without the statement around it.

since Player is plr.Name, you’re doing plr.Name.Name. Change it to just Player. Unless you changed the Player variable?

if game.Players:FindFirstChild(Player).leaderstats.Kicks.Value == 100 then

You’re actively confusing yourself when making the Player variable its name
Maybe if instead of

local Player = plr.Name

you do

local PlayerName = plr.Name

I tested these changes, and it thinks that the Kicks value is still not 100, when it clearly shows 100 kicks in the leaderboard.
Note: I’m about to go eat dinner, and I won’t be here for around an hour.

How did you change the value? Possible you changed it on the client and it’s the same on the server.

1 Like

So it does work, but your code doesn’t?
The error is saying that Player doesn’t exist. How are you defining it?

line 2,

local PlayerName = plr.Name

it was changed on the client. it finally works, now that i changed the value on serverside. thank you for helping.

1 Like

the ban script works, obviously, and @Zerin107 has helped my code work. Thank you for your help.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.