Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Need assistance on a AFK Kick script, can someone explain me a few things?

local plrs = game.Players:GetPlayers()

game.Players.plrs.Idled:connect(function(time)

end)

-- I'm really sorry that's all I have, I'm still learning so it is quite difficult to me to figure things out by myself, thanks for your attention!

Hello! I just started scripting in Lua and I didn't quite get the onPlayerAdded and Idle thing, can someone help me? Thank you!

1 answer

✓ Accepted answer

I don't see an onPlayerAdded in your script, but I'll try to explain Idled first.

Idled is an event of the Player object. When you Connect an event (you should use Connect, not connect because the lowercase version is deprecated) to a function, the function will run every time the event triggers.

In this case, Idled is triggered when the game engine classifies the player as idle (no actions have been made for a long time). I found this out by simply going to the wiki. It says the event will usually trigger every 2 minutes while the player is idle.

The time parameter in brackets is information that is sent when the event triggers. In this case, the information is the amount of time in seconds that the player has been idle for. So if you ever use that in your function, simply reference it in your code by typing time (or if you change the name, keep the variable name consistent).

I hope that part makes sense.

You mentioned onPlayerAdded but never showed it in your script, however I can explain the event.

PlayerAdded is an event that fires whenever a player joins the game. The name onPlayerAdded tells me that it is the function that is fired when this event triggers. It would look something like this:

local function onPlayerAdded(player) -- event sends the player when the event is triggered
	-- whatever you want to do when player joins the game
end

game.Players.PlayerAdded:Connect(onPlayerAdded)
-- PlayerAdded is an event of the Players service
-- I connected it to the onPlayerAdded function
-- Notice how I wrote onPlayerAdded and not onPlayerAdded() with brackets!

Hope this helps!

2 comments

0

unexpected ')' near 'end'

0

oof man im out of it today lol

This discussion is preserved as it was. New answers, comments, and votes are closed.