How do i hide overhead guis?

Im making a simulator game that has overhead guis to show stats, As you can imagine about 10 stats have been made and it looks very messy to see everyone elses overhead gui.
Ive seen it implemented in other games but, how would i go around making a button to hide others overhead gui whilst keeping your own.

TIA

1 Like

If youā€™re referring to Robloxā€™s Overhead GUIs, You can do it with this API:

No, Sorry for not clarifying, There custom made GUIā€™s overhead to show users stats.

1 Like

Every BillboardGui instance has a property called PlayerToHideFrom. To make it so that you cannot see anyone elseā€™s nametag, you could use a LocalScript to change this property.

Alright - this has no exact solution because it depends on how you implement it, but I can give you some pseudocode to help you.

There is no in-engine way to do this (i.e. something like GUI:SetViewableBy(Player, false)) unfortunately, however it should be pretty easy to implement:

local ToggleValue = true
ButtonPressEvent:Connect(function()
    ToggleValue = not ToggleValue
    for _, Player in pairs(Players:GetPlayers()) do
        if Player.UserId ~= LocalPlayer.UserId 
        and Player.Character 
        and Player.Character:FindFirstChild("MyAwesomeHeadsUp") then
            Player.Character.MyAwesomeHeadsUp.Enabled = ToggleValue
        end
    end
end)

Youā€™d then need to listen to every new character added and do that logic on it to make sure new players / respawned characters are affected.

Okay thank you ill give this a go. Also new to scripting and have wondered this for a while what is the ā€œfor_, Playerā€
actually do? I see all these _, but never know what they do.

Sure thing! :stuck_out_tongue:
_ is basically a key for sink this parameter - so, donā€™t allocate anything to me.
It functions, in a way, like /dev/null on Linux - itā€™s like a Variable hole that you can assign things to but not reference it. So, you should use it if you have a function, loop or callback that receives more arguments than it needs.

For example:

function getPlayerStuff(_, _, Hi)
    print(Hi)
end
getPlayerStuff("Hello", "Hey", "Wazzup")

Output:

Wazzup


EDIT: I forgot to say why this is useful!

Letā€™s say you have a Roblox function that you give a callback, such as UserInputService:InputBegan. This callback is given two inputs:

  • InputObject - All the information about what the userā€™s action was
  • GameProcessed - If the input was sunk by a Roblox Interface

If you only wanted the second argument for your function, youā€™d do this:

function gameProcessed(_, GameProcessed)
   print(GameProcessed)
end
UserInputService.InputBegan:Connect(gameProcessed)
1 Like

Thank you, So for example in for i,v in pairs() there would be no index if i replaced it with for _, v in pairs() and allows the value to be set at a later time?

Well, you canā€™t set it at a later time, but youā€™d be able to set i to something without overriding.

Itā€™s useful to have this because itā€™s good practice to not assign variables to stuff you donā€™t use. In the Lua Stack, the function will look something very loosely like this: (warning: my understanding of Lua internals is about the same as a 5 year oldā€™s understanding of Quantum Dynamics)

---- Function Pointer
--- address of argument 1
--- address of argument 2
--- return pointers
-- program instructions
..
..
..
..
----

So, the more things you assign to variables, the more memory youā€™re using up.

Okay thank you for the help :grinning: , So its to save data and you should never assign a value to something not being used at that time

Pretty much! Hope that helps. Iā€™m sure someone can explain it a lot better though.

If youā€™re somehow bedstruck for multiple years, and looking for the last resort of reading materials, perhaps take a look at the Lua 5.3 Technical Manual (although Roblox runs its own custom environment based off of Lua 5.1).

The same details should be the same, though. Itā€™s not something Iā€™d rĢ“eĢ·cĢ·oĢ“mĢ“mĢ“eĢ·nĢ·dĢ“ you readĢ“ĢŒĶœĢ¼ idly. MĢ¶oĢ“sĢµtĢ· Ģ¶SĢøoĢ·uĢølĢ·sĢø do noĢ¶t retĢ·uĢ¶rĢ¶nĢµ iĢ“ĶĢƒĶ‰nĢµĢĶ‰ĶŽtĢµĢšĢ™oĢ·Ģ†ĢŗĶ• Ģ“Ķ—Ķ‹Ģ²tĢ“ĢƒĢ„Ķ™hĢ·Ģ‰Ģ—eĢøĢ‹Ģ” light.

1 Like

Thank you, ill check it out at some point as i said im relatively new to scripting but i can script quite a few different things just learning how to do more :slight_smile:

1 Like

Yes this also works. If you dont want a claster between the Player name and the stats

1 Like

Can you clarify what you mean by a ā€œclasterā€ ? I havenā€™t come across it.

I meant if you do not want the the Playerā€™s name and the data to be mixed up or on the same level or just simply remove it. (Sorry for the mix of words im new to Developing :blush:

1 Like

I dont know if im just stupid but

local Toggle = true
local Players = game:WaitForChild("Players")

script.Parent.MouseButton1Click:Connect(function()	
	
	if Toggle.Value == true then 
		Toggle.Value = false
	else
			Toggle.Value = true
	end


	if Toggle.Value == false then
		for _, player in pairs(Players:GetChildren()) do
			if player.UserId ~= game.Players.LocalPlayer.UserId
				and player.Character
				and player.Character:FindFirstChild("OverHead") then
				player.Character.Overhead.Enabled = false
				Toggle.Value = false
			end
		end
		
	else
		for _, player in pairs(Players:GetChildren()) do
			if player.UserId ~= game.Players.LocalPlayer.UserId
				and player.Character
				and player.Character:FindFirstChild("OverHead") then
				player.Character.Overhead.Enabled = true
				Toggle.Value = true
			end
		end
	end
end)
1 Like

If iā€™d go about doing this with a Gui Billboard then:

When the player turns them off iā€™d loop through the Workspace OR if you have put the player characters
somewhere else then loop through that. And locally hide that gui from the user. making that gui not visible to said user and doesnā€™t replicate across user to user nor server.

Or alternitively you can simply set Enable to false and it would work the sameā€¦
All you need to do is make sure this is done via a local script.