AFK problem pls help

I tried to make the afk system, but when I clicked the afk button, the game started. Can you take a look at a script?

how can i solve
isAFK script:

local remote = game.ReplicatedStorage.isAFK

remote.OnServerEvent:Connect(function(player, isAFK)
	
	if isAFK == "AFK" then
		
		local afkVal = Instance.new("BoolValue")
		afkVal.Name = "isAFK"
		afkVal.Parent = player
		
	else
		
		player.isAFK:Destroy()
		
	end
	
end)

Main script( what should I do?):

for i, player in pairs(plrs) do
		if player then
			character = player.Character
			
				if character then
				
				character:FindFirstChild("HumanoidRootPart").CFrame = AvailableSpawnPoints[1].CFrame + Vector3.new(0,10,0)
				table.remove(AvailableSpawnPoints,1)


				-- Give them a gear
				local equipped = game.ServerStorage.PlayerData[player.Name].Equipped

				if equipped.Value ~= "" then
					local weapon = game.ServerStorage.Items[equipped.Value]:Clone()
					weapon.Parent = player.Backpack
				else
					local ClassicSword = ServerStorage.ClassicSword:Clone()
					ClassicSword.Parent = player.Backpack
				end


				local GameTag = Instance.new("BoolValue")
				GameTag.Name = "GameTag"
				GameTag.Parent = player.Character
				
			else
				-- There is no character
				if not player then
					table.remove(plrs,i)
				end
			end
			end	
		
		if character:FindFirstChild("isAFK") then

			character:FindFirstChild("HumanoidRootPart").CFrame = AvailableSpawnPoints[1].CFrame + Vector3.new(0,10,0)
			table.remove(AvailableSpawnPoints,1)


			-- Give them a gear
			local equipped = game.ServerStorage.PlayerData[player.Name].Equipped

			if equipped.Value ~= "" then
				local weapon = game.ServerStorage.Items[equipped.Value]:Clone()
				weapon.Parent = player.Backpack
			else
				local ClassicSword = ServerStorage.ClassicSword:Clone()
				ClassicSword.Parent = player.Backpack
			end


			local GameTag = Instance.new("BoolValue")
			GameTag.Name = "GameTag"
			GameTag.Parent = player.Character

		else
			-- There is no character
			if not player then
				table.remove(plrs,i)
			end
		end
	end

Video:

1 Like

You forgot to make it if NOT character findfirstchild isafk
Also a tip, instead of using for i,v in ipairs or pairs, use for i,v in next, part:getchildren() do
Next is faster than ipairs and pairs and even tho its like a few miliseconds, it will still help.
Here is fixed code:

for i, player in next, plrs do
	if player then
		character = player.Character

		if character then

			character:FindFirstChild("HumanoidRootPart").CFrame = AvailableSpawnPoints[1].CFrame + Vector3.new(0,10,0)
			table.remove(AvailableSpawnPoints,1)


			-- Give them a gear
			local equipped = game.ServerStorage.PlayerData[player.Name].Equipped

			if equipped.Value ~= "" then
				local weapon = game.ServerStorage.Items[equipped.Value]:Clone()
				weapon.Parent = player.Backpack
			else
				local ClassicSword = ServerStorage.ClassicSword:Clone()
				ClassicSword.Parent = player.Backpack
			end


			local GameTag = Instance.new("BoolValue")
			GameTag.Name = "GameTag"
			GameTag.Parent = player.Character

		else
			-- There is no character
			if not player then
				table.remove(plrs,i)
			end
		end
	end	

	if not character:FindFirstChild("isAFK") then 

		character:FindFirstChild("HumanoidRootPart").CFrame = AvailableSpawnPoints[1].CFrame + Vector3.new(0,10,0)
		table.remove(AvailableSpawnPoints,1)


		-- Give them a gear
		local equipped = game.ServerStorage.PlayerData[player.Name].Equipped

		if equipped.Value ~= "" then
			local weapon = game.ServerStorage.Items[equipped.Value]:Clone()
			weapon.Parent = player.Backpack
		else
			local ClassicSword = ServerStorage.ClassicSword:Clone()
			ClassicSword.Parent = player.Backpack
		end


		local GameTag = Instance.new("BoolValue")
		GameTag.Name = "GameTag"
		GameTag.Parent = player.Character

	else
		--logic idk
	end
end

i removed some code because i didnt understand your stuff fully

5 Likes

what I have to give???

2 Likes

What do you mean by that?? (ignore this)

1 Like

Im using translate i don’t know what you mean, can you send the code directly

1 Like
	if player then
		character = player.Character

		if character then

			character:FindFirstChild("HumanoidRootPart").CFrame = AvailableSpawnPoints[1].CFrame + Vector3.new(0,10,0)
			table.remove(AvailableSpawnPoints,1)


			-- Give them a gear
			local equipped = game.ServerStorage.PlayerData[player.Name].Equipped

			if equipped.Value ~= "" then
				local weapon = game.ServerStorage.Items[equipped.Value]:Clone()
				weapon.Parent = player.Backpack
			else
				local ClassicSword = ServerStorage.ClassicSword:Clone()
				ClassicSword.Parent = player.Backpack
			end


			local GameTag = Instance.new("BoolValue")
			GameTag.Name = "GameTag"
			GameTag.Parent = player.Character

		else
			-- There is no character
			if not player then
				table.remove(plrs,i)
			end
		end
	end	

	if not character:FindFirstChild("isAFK") then 

		character:FindFirstChild("HumanoidRootPart").CFrame = AvailableSpawnPoints[1].CFrame + Vector3.new(0,10,0)
		table.remove(AvailableSpawnPoints,1)


		-- Give them a gear
		local equipped = game.ServerStorage.PlayerData[player.Name].Equipped

		if equipped.Value ~= "" then
			local weapon = game.ServerStorage.Items[equipped.Value]:Clone()
			weapon.Parent = player.Backpack
		else
			local ClassicSword = ServerStorage.ClassicSword:Clone()
			ClassicSword.Parent = player.Backpack
		end


		local GameTag = Instance.new("BoolValue")
		GameTag.Name = "GameTag"
		GameTag.Parent = player.Character

	else
		--logic idk
	end
end```
main code
1 Like

shall I assign the code to you completely

Just replace main code with that it should work

not Working ((((((()))))))))))

Then i don’t know, try getting someone more experienced

Have you tried UserInputService?

You don’t ever actually do anything to check if they aren’t AFK. From what I see, you check if they are AFK and then keep rubbing code. Nothing is stopping the game from actually running

1 Like

I can’t really fine an exact solution. Could you post the code of the local script of when the button is clicked? Also, if character:FindFirstChild(“isAFK”) then end if statement seems to run the same code as the if character then end statement.

okay
Script:

local plr = game.Players.LocalPlayer
local button = script.Parent
local remote = game.ReplicatedStorage.isAFK

button.MouseButton1Click:Connect(function()
	
	if not plr:FindFirstChild("isAFK") then
		
		button.Text = "Not AFK"
		remote:FireServer("AFK")
		
		
	else
		
		button.Text = "AFK"
		remote:FireServer("not AFK")
		
	end
end)

Shall I send you the full of the main script?