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.
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!
_ 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)
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.
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.
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
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
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)
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.