Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make a script to kick AFK players?

Asked by 7 years ago

I need a script that kickes AFK players after a choosen time.

0
Examples of you actually trying to do this? BinaryResolved 215 — 7y
0
Since you haven't included any bit of your own attempts, I will not write the script for you, BUT I will try to help. An easy way to do this is to create a timer that is reset when ANY key bind is pressed. So that if no one presses any keys for a certain amount of time, the game kicks them. BSIncorporated 640 — 7y
0
BSI that's a very difficult way to do a much more simple thing (See my answer below) Tempestatem 884 — 7y
0
I tried making a function that is only called when a certain time is achieved but it didn't work, ArcanZus 61 — 7y
0
Show your script in the question then, and I can take a look at it. Tempestatem 884 — 7y

1 answer

Log in to vote
1
Answered by 7 years ago
Edited 7 years ago

This isn't a request site, but I can certainly show you what you need to do!

(Note: Do not use a localscript, because you cannot kick a player with one)

What you can do is make a script and in it use an event with the player called Idled.

In essence this fires after two minutes of the player being "idle". Normally ROBLOX will automatically kick any player who is idle in game for 20 minutes. After two minutes, the event will be fired (sort of updating if you will) until the player is no longer idle, or after 20 minutes is kicked.

Of course you need to get the player before doing this, so what I personally would do is use the PlayerAdded event.

With simple knowledge of coding, you can implement this perfectly into your code to make it work just as you want!

Here is the example code on the wiki page, i'll try to break it down for you:

game.Players.Player.Idled:connect(function(time) -- This is the function, of course you have to define "Player", but that can easily be done by using the PlayerAdded function. time is simply how long the player has been idle 
     print("Player has been idle for " .. time .. " seconds") -- If the player had been idle for 300 seconds, this would print in the output "Player has been idle for 300 seconds". You could use an if statement, to check when the time is at the point when you want to kick.
end)

I hope this helps! Here's some more wiki links to anything you may need to know (In case you are extremely new to coding)

Conditional Statements (If statement)

Kick()

Events

Ad

Answer this question