I just started working on adding an AFK button to my game's settings and was wondering how I would rewrite my current code to check if the player is AFK and only affect players that are not AFK
local seconds = game.Workspace.Time
local title = game.Workspace.Title
local ingame = game.Workspace.InGame.Value
local players = game.Workspace.PlayersInRound
local event = game.ReplicatedStorage.Events.ChosenMap
local Map
while true do
wait(1)
seconds.Value = seconds.Value - 1
if seconds.Value == 0 and ingame == 0 then
local chosenMap = math.random(1,5)
Map = game.ReplicatedStorage.Maps:FindFirstChild("Map"..chosenMap):Clone()
Map.Parent = game.Workspace
ingame = 2
title.Value = "TELEPORTING PLAYERS IN"
seconds.Value = 10
game.Workspace.Lobby.NSpawner.Enabled = false
local teleport = game.Players:GetChildren()
for i = 1, #teleport do
teleport[i]:LoadCharacter()
teleport[i].Character.Humanoid.WalkSpeed = 0
end
event:FireAllClients(chosenMap)
end
if seconds.Value == 0 and ingame == 1 then
ingame = 0
title.Value = "INTERMISSION"
seconds.Value = 30
local teleport = game.Players:GetChildren()
for i = 1, #teleport do
teleport[i]:LoadCharacter()
end
Map:Destroy()
elseif players.Value <= 0 and ingame == 1 then
ingame = 0
title.Value = "INTERMISSION"
seconds.Value = 30
local teleport = game.Players:GetChildren()
for i = 1, #teleport do
teleport[i]:LoadCharacter()
end
Map:Destroy()
end
if seconds.Value == 0 and ingame == 2 then
ingame = 1
title.Value = "ROUND ENDS IN"
seconds.Value = 60
game.Workspace.Lobby.NSpawner.Enabled = true
local teleport = game.Players:GetChildren()
for i = 1, #teleport do
teleport[i].Character:MoveTo(Vector3.new(-1000, 3, 0))
teleport[i].Character.Humanoid.WalkSpeed = 16
players.Value = #teleport
end
end
end

1 comment
Sorry if this is something easy I'm still learning how to script.