Overhead Gui appears and disappears upon button click

Greetings developers!

If you have played Meep City recently, you noticed that when a player goes into avatar editor mode, a GUI will pop over his head. I want to do the same thing with my game.

local billboardgui = game:GetService("ServerStorage"):WaitForChild("BillboardGui")

local HomeButton = game.Players.LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("Menu"):WaitForChild("BackFrame"):WaitForChild("Home")
local ClubButton = game.Workspace:WaitForChild("MainMenu"):WaitForChild("BillboardMenu"):WaitForChild("StartButton"):WaitForChild("SurfaceGui"):WaitForChild("TextButton")

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		print("Gui Added")
		local clonedgui = billboardgui:Clone()
		clonedgui.Parent = game.Workspace:WaitForChild(player.Name).Head
		clonedgui.Enabled = false
		
			HomeButton.MouseButton1Click:Connect(function()
				print("Afk")
				clonedgui.Enabled = true
			end)
		
			ClubButton.MouseButton1Click:Connect(function()
				clonedgui.Enabled = false
			end)
	end)
end)

I get an error which says that i am trying to index nil with WaitForChild while defining HomeButton

Placement of each button and the GUI :

Thank you so much for helping!

The LocalPlayer is limited to LocalScripts, I don’t understand why you’re doing this when you have the Player (defined as player) inside the PlayerAdded function and can reach their PlayerGui right there.

A better solution would be to integrate a RemoteEvent to toggle the HomeButton remotely in a LocalScript within the UI.

2 Likes