Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Hide multiple frames at once?

Asked by 3 years ago

Is there a way to set the visible of multiple frames to falsest at once? something like:

--// Variables
local HUD = script.Parent.Parent.HUD
local plr = game.Players.LocalPlayer
--// Show/Hide HUD
plr:GetMouse () .KeyDown:Connect(function(Y)
    if Y == "y" then
        HUD:GetChildren().Visible = false
    end
end)

2 answers

Log in to vote
0
Answered by
Leamir 3138 Moderation Voter Community Moderator
3 years ago
Edited 3 years ago

Hello, loganmatt3!

That can be easily solved using a For Loop, more specifically, using it to iterate throught the array that is returned by :GetChildren().

More information about it can be found on:

https://education.roblox.com/en-us/resources/pairs-and-ipairs-intro

https://developer.roblox.com/en-us/articles/Loops


I also noticied you are using Mouse to detect when a key is pressed, you should be using UserInputService to detect it, as Mouse.KeyDown was deprecated some years ago.

More information can be found here:

https://developer.roblox.com/en-us/api-reference/class/UserInputService

https://developer.roblox.com/en-us/api-reference/class/Mouse


If this answer helps you, please mark it as "accepted"

Good luck with your games

0
An easier solution would be to (if he/she wants to hide everything from the Gui) just disable/enable it. When it's something like If not Y == "y" then HUD.Enabled = true, let me know if this seems like an easier solution qMrSpooky 20 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

If you want to disable all of the frames in a Gui, do this:

local player = game.Players.LocalPlayer -- get player
local GUI = player.PlayerGui.YourGuiHere -- Get the Player's Gui (Change it to what you have)

player:GetMouse () .KeyDown:Connect(function(Y)
    if Y == "y" then
        GUI.Enabled = false
    end
end)

If there's anything wrong let me know.

Answer this question