Trying to fix the current AFK system!

local event = game:GetService("ReplicatedStorage"):WaitForChild("AFKRemote")
--local T=game.ReplicatedStorage:WaitForChild("Time")

event.OnServerEvent:Connect(function(player)
	
	if player.AFK.Value == true and #game.Workspace.MainFrame.InRound:GetChildren() == nil then
		local val = Instance.new("StringValue")
		val.Name = player.Name 
		val.Parent = game.Workspace.MainFrame.InRound
		player.AFK.Value = false
		print("Player no longer AFK")
	else
		while game.Workspace.MainFrame.InRound:FindFirstChild(player.Name) == nil do
			wait(1)
			print("Player is not in round!")
			player.AFK.Value = true
		end
		
		game.Workspace.MainFrame.InRound:FindFirstChild(player.Name):Destroy()
		player.AFK.Value = true
		print("Player currently AFK")
		
		--[[while player.AFK.Value == false do
			wait(5)
			game.Workspace.MainFrame.InRound:WaitForChild(player.Name):Destroy()
		end]]--
		
	
	end
end)

This is my script in ServerScriptService and It’s called RemoteEventHandler which then the button is clicked it will fire an event which will change the player.AFK.Value to false so that the player is afk and not in the game. So after each game it will add the player to the InRound folder even while the afk is false. Is there anyway for the script to constanly :Destroy() the player when the value is false. As you can see in the comments that is the new part I added. I’m still learning to script and I’ve trying to figure this out for a while now.

So what I am trying to figure out is there a way to destroy the players name from the Inrounds Folder while the Value being false. It only does it once.

This is the current script main script which handles the players:

local function intermission()
	repeat wait()
		local player=game.Players:GetChildren()
		for i=1,#player do
			local val=Instance.new("StringValue")
			val.Name=player[i].Name
			val.Parent=game.Workspace.MainFrame.InRound
		end
		while #game.Workspace.MainFrame.InRound:GetDescendants()<minPlayers do
			M.Value=(minPlayers.." Players are required to play...")
			wait(1)
		end
		for i=10,0,-1 do
			T.Value=i
			wait(1)	
		end
		local GS=0--GS=Game Starting
		M.Value = (minPlayers.." Players are required to play...")
	until #game.Workspace.MainFrame.InRound:GetDescendants() >= minPlayers 
	wait(1)
	local GS=0--GS=Game Starting
	repeat
		M.Value="Game Starting."
		wait(0.3)
		M.Value="Game Starting.."
		wait(0.3)
		M.Value="Game Starting..."
		wait(0.3)
		GS=GS+1
	until GS==2
end

This is the settings Script which toggles it:

local player = game.Players.LocalPlayer
local trigger = true -- On {0.25, 0},{0.5, 0} c =34, 255, 0
local Remote = game:GetService("ReplicatedStorage"):WaitForChild("AFKRemote") 

script.Parent.MouseButton1Click:Connect(function()
	if trigger == true then
		print("You are now AFK")
		Remote:FireServer()
		script.Parent.Parent.Move:TweenPosition(UDim2.new(0.25, 0, 0.5, 0), "Out", "Quart", 0.3)
		script.Parent.Parent.Move.ImageColor3 = Color3.fromRGB(34, 255, 0)
		trigger = false
	else
		print("You are not afk")
		script.Parent.Parent.Move:TweenPosition(UDim2.new(0.75, 0, 0.5, 0), "Out", "Quart", 0.3)
		script.Parent.Parent.Move.ImageColor3 = Color3.fromRGB(255, 78, 81)
		trigger = true
	end
end)

Actually its easy, don’t add the stringvalue at the on server event.

Then you can just iterate through the string values at InRound and then find the player with its name, when you find it teleports

So I need to not add the stringvalue in the RemoteEventHandler Script?

At the AFK remote you remove the val.Parent = game.Workspace.MainFrame.InRound

It still adds me to the round.

the AFK remote just adds you back if you decide to come back. There’s a problem with the main script. I tried making a while Player.AFK.Value ~= true then destroy() there name but that didn’t work.

I dont see the script that teleports you to the game…

It only teleports people that are in the InRounds folder. The teleport script doesn’t effect the InRounds folder.

The Teleport Script:

local function Teleport()
	local playing = game.Workspace.MainFrame.InRound:GetChildren()
	for i=1,#playing do
		local done=false 
		local p=game.Workspace:FindFirstChild(playing[i].Name)
		for _,v in pairs(game.Workspace.Map:GetChildren())do
			if done == false then
				if v.Value.Value==false then
					local c=game.Workspace.MainFrame.InRound:GetChildren()
					local p=game.Workspace:FindFirstChild(playing[i].Name)
					p.HumanoidRootPart.Position=v.Position+Vector3.new(0,6,0)
					p.Humanoid.WalkSpeed=0
					v.Value.Value=true
					done=true
				end
			end				
		end
	end

Just noticed this but you simply didnt add any conditionals to if the player is afk or not.

You could simply add this:

if player[i]:FindFirstChild("AFK").Value == false then
      --The code to put the players which would be the code i quoted
end

-- You could do if not player[i]:FindFirstChild("AFK").Value then