Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can i make this code not work when this GUI element isnt visible?

Hello, im trying to make it so when a player pressed C when a GUI element is visible it does something, but when the GUI element isnt visible, players are still able to press C to make that something appear. Here is the code:

local Enabled = false
local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(input, gameProcessedEvent)
	if input.KeyCode == Enum.KeyCode.C then
		if not Enabled then
			Enabled = true
			game.Players.LocalPlayer.Backpack.Camera1.Disabled = false
			game.Players.LocalPlayer.PlayerGui.camgui.CamButtons.Visible = true
			game.Workspace.CameraDummy1.Transparency = 1
		else
			Enabled = false
			game.Players.LocalPlayer.PlayerGui.camgui.CamButtons.Visible = false
			workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
			game.Players.LocalPlayer.Backpack.Camera2.Disabled = true
			game.Players.LocalPlayer.Backpack.Camera1.Disabled = true
			game.Players.LocalPlayer.Backpack.Camera3.Disabled = true
		end
	end
end)

Ive tried putting it in an if game.Players.LocalPlayer.PlayerGui.camgui.maincambutt.Visible = true then but it didnt work, i also added an else if game.Players.LocalPlayer.PlayerGui.camgui.maincambutt.Visible = false and it didnt work. To clarify, im trying to make it so when a GUI element is visible on a screen a KeyCode will work, and when its not visible the KeyCode wont work.

Im also doing this in a Local Script.

2 comments

0

try: if not game.Players.LocalPlayer.PlayerGui.camgui.CamButtons.Visible then

0

doesnt seem to work...

1 answer

If you want the code to not work when the UI isn't visible and not a boolean in the script, I would change the

local Enabled = false

to

local Enabled = GUI.Visible --Make GUI the gui you want to use

1 comment

0

this doesnt seem to resolve my issue, i can give more information if needed

This discussion is preserved as it was. New answers, comments, and votes are closed.