AFK overhead gui

Hi, i’m trying to make an overhead gui that adds “[AFK]” to their nametag when they tab out of the window. The afk dosent show up, can someone explain whats the problem?

ServerScriptService script:

local AFKStatus = {}
local AFKEvent = game.ReplicatedStorage:FindFirstChild("AFK")


if not AFKEvent then
	AFKEvent = Instance.new("RemoteEvent")
	AFKEvent.Parent = game.ReplicatedStorage
	AFKEvent.Name = "AFK"
end

local updateAFK = function(player,enable)
	
	local GUI = player.Character:WaitForChild("Head"):WaitForChild("NametagGui")
	local AFKTagT = GUI:WaitForChild("UpperText")
	
	if enable then
		AFKTagT.Text = player.DisplayName.."[AFK]"
	else
		AFKTagT.Text = player.DisplayName
	end
end


AFKEvent.OnServerEvent:Connect(function(player,enable)
	AFKStatus[player] = enable
	updateAFK(player,enable)
end)

StarterCharacterScripts Local Script:

local ReplicatedStorageEvent = game.Workspace:WaitForChild("AFK")

game:GetService("UserInputService").WindowFocusReleased:Connect(function()

ReplicatedStorageEvent:FireServer(true)

end)

game:GetService("UserInputService").WindowFocused:Connect(function()

ReplicatedStorageEvent:FireServer(false)

end)

Thank u!

1 Like

Did you reference it incorrectly? In the server script you reference it in ReplicatedStorage, but in the localscript you reference it as if it were in Workspace.

3 Likes

Thank u a lot! That was the issue, I didnt notice at all. Have a nice day!

3 Likes