AFK Bug (Boolean)

I got a bug with afk. I have this script in ServerScriptService:

while true do
 for _,v in pairs(game.Player:GetChildren()) do -- i also tried with "GetPlayers()"
  if v.afk.Value then -- boolean afk value
    print("player is afk but it still teleports him because of")
  else
    v.Character:MoveTo(workspace.Spawn.Position)
  end
 end
end 

The player is teleported even if he has afk mode turned on, that is, boolean value. I think the problem is with “while true do” but I don’t know what exactly, I tried to add afk mode in way “StarterPlayer > StarterCharacterScripts” (like in character) but the same thing happened

1 Like
while true do
 for _,v in pairs(game.Player:GetChildren()) do -- i also tried with "GetPlayers()"
  if v.afk.Value == true then -- boolean afk value --and set the obj value to true and see if it works
    print("player is afk but it still teleports him because of")
  else
    v.Character:MoveTo(workspace.Spawn.Position)
  end
 end
end```
3 Likes

same bug :frowning: I guess script seems to determine the value of afk only once

2 Likes

do you mean it only loops once
or it only works for a single player

1 Like

Are you changing the afk value through the client?
Then it won’t replicate on the server.

It could also be a script timeout due the while true do Loop, just change that with
while task.wait() do.
Just heads up!

4 Likes

thanks, worked through RemoteEvents

2 Likes