SUPPORT NEEDED AFK Timer [Nametag]

I am trying to format my afk timer so it is like 01:00 insted of 1:0
An example of this working is on GRP could anyone help me figure out how to do something like it?

Current Code

local AfkEvent = Instance.new("RemoteEvent")
AfkEvent.Name = "AfkEvent"
AfkEvent.Parent = ReplicatedStorage

local function setAfk(player, afk)
	if afk then

		local time1 = 0


		local Nametag = player.Character.HumanoidRootPart.NameTag.afk
		local Nametag1 = player.Character.HumanoidRootPart.NameTag.afktag
		local time1 = 0
		Nametag1.Visible = true
		Nametag.Visible = true

		if Nametag.Visible == true then
			time1 = 1
			repeat 

				wait(1)
				time1 = time1 + 1

				if time1 < 60 then
					Nametag.Text = "00:"..time1 
				end

				if time1 >= 60 then
					local timemin = time1 - 60
					Nametag.Text = "01:"..timemin 
				end

				if time1 >= 120 then
					local timemin1 = time1 - 120
					Nametag.Text = "02:"..timemin1 
				end

				if time1 >= 180  then
					local timemin2 = time1 - 180
					Nametag.Text = "03:"..timemin2 
				end

				if time1 >= 240  then
					local timemin3 = time1 - 240
					Nametag.Text = "04:"..timemin3  
				end

				if time1 >= 300 then
					local timemin4 = time1 - 300
					Nametag.Text = "05:"..timemin4 
				end

				if time1 >= 360  then
					local timemin5 = time1 - 360
					Nametag.Text = "06:"..timemin5 
				end

				if time1 >= 420 then
					local timemin6 = time1 - 420
					Nametag.Text = "07:"..timemin6 
				end

				if time1 >= 480 then
					local timemin7 = time1 - 480
					Nametag.Text = "08:"..timemin7 
				end

				if time1 >= 540 then
					local timemin8 = time1 - 540
					Nametag.Text = "09:"..timemin8 
				end

				if time1 >= 600 then
					local timemin9 = time1 - 600
					Nametag.Text = "10:"..timemin9 
				end

			until Nametag.Visible == false
		end


	else
		local Nametag1 = player.Character.HumanoidRootPart.NameTag.afktag
		local Nametag = player.Character.HumanoidRootPart.NameTag.afk
		Nametag.Visible = false 
		Nametag1.Visible = false
		Nametag.Text = "00:00"
	end
end



AfkEvent.OnServerEvent:Connect(setAfk)```

Come across this response to a different ticket that has some string manipulation/regex that may be of use to you.

I do not fully understand this however thanks for trying to help.

  • kieranl29_#3816

Help needed.

Not Working Code

Server Script

local AfkEvent = Instance.new("RemoteEvent")
AfkEvent.Name = "AfkEvent"
AfkEvent.Parent = ReplicatedStorage


local minutes = 0
local seconds = 0
local stop = false


function startTimer(player, afk)
	if afk == true then

		if seconds == nil and minutes == nil then
			seconds = 0
			minutes = 0		
			wait(0.5)
		else
--[[	if minutes ~= 0 or seconds ~= 0 then
		minutes = 0
		seconds = 0
		end
	]]	

			repeat
				local character = player.Character
				local nametag = character:WaitForChild("HumanoidRootPart"):WaitForChild("NameTag").AFK_Moduel.afk_timer
				local nametagTwo = character:WaitForChild("HumanoidRootPart"):WaitForChild("NameTag").AFK_Moduel.afk

				nametag.Visible = true
				nametagTwo.Visible = true



				if minutes < 10 then	
					nametag.Text = string.format("0%d:%02d", minutes, seconds)
				else
					nametag.Text = string.format("%d:%02d", minutes, seconds)
				end

				wait(1)
				seconds = seconds + 1

				if seconds == 60 then
					seconds = 0
					minutes += 1
				end

				print(tostring(seconds))
				print(tostring(minutes))

			until stop == true
		end

		if afk == false then
			stop = true
			local character = player.Character
			local nametag = character:WaitForChild("HumanoidRootPart"):WaitForChild("NameTag").AFK_Moduel.afk_timer
			local nametagTwo = character:WaitForChild("HumanoidRootPart"):WaitForChild("NameTag").AFK_Moduel.afk

			nametag.Visible = false
			nametagTwo.Visible = false
		end
	end
end


AfkEvent.OnServerEvent:Connect(startTimer)```
Local Script
local Players = game:GetService("Players")
local player = Players.LocalPlayer

local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local AfkEvent = ReplicatedStorage:WaitForChild("AfkEvent")

local function focusGained()
	AfkEvent:FireServer(false)	
end

local function focusReleased()
	AfkEvent:FireServer(true)
end

UserInputService.WindowFocused:Connect(focusGained)
UserInputService.WindowFocusReleased:Connect(focusReleased)```

NVM it stopped working

Not sure if this can contribute you something.

RequiredForMinute = 60
Minutes = 0
Seconds = 0

while true do
    if Seconds == RequiredForMinute then
        Minutes += 1
        Seconds = 0
    end
    Seconds += 1
    wait(1)
end

thanks for the help but i think it is the local script. I just printed afk and it keeps going to false although i am afk.

If @ClanAtlas could help I would love that!

1 Like

Hey sorry I didn’t work on the afk system for GRP, and I can’t check now because I’m retired. I wish you the best of luck!

2 Likes