Gui visible only when holding key

Hey there, fellow devs!

So, I’ve been making a shooting game with my friend recently, but I’m stuck at the tab leaderboard. Like you know? Phantom forces and arsenal has that leaderboard. A GUI which is only visible when you hold tab (Enum.KeyCode.Tab).

There are multiple posts on this topic. I’ve tried all of them but I’ve still not came up to a solution. It’d be great if anybody could help! Thanks!

  • AridFights1
1 Like

https://developer.roblox.com/en-us/api-reference/event/UserInputService/InputBegan
https://developer.roblox.com/en-us/api-reference/event/UserInputService/InputEnded

InputBegan fires then make the GUI visible, InputEnded fires then make the GUI not visible.

2 Likes

You can use the KeyDown and the KeyUp events that are provided by the mouse by using player:GetMouse()

2 Likes

I’ve tried both of them, even in a normal baseplate. But still doesn’t seem to work. I’ll try again and let you know what happens.

1 Like

Alright, provide your code if there is still problems.

1 Like

Okay, I’ll try that. Thanks for the replies!

1 Like

It could be an issue with how you set up the code and or the script. Make sure you use UserInputService in a localscript and make sure it is placed somewhere that allows localscripts to run, in your case, probably inside of the leaderboard screengui

2 Likes

Yeah, mine is in the frame (the leaderboard).

1 Like

Well that’s weird. Somehow it worked even though I did the exact same thing in the main game. Might’ve been a studio bug (Even though I restarted it multiple times), or my script was messed up who knows? Anyways, thanks a lot for the help!

Thanks to:

  1. @Quwanterz;
  2. @Arcilios;
  3. @EmbatTheHybrid!

For anybody who wants to know the code, here it is:

(Please don’t care about the messy code)
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, false)

local u = game:GetService("UserInputService")
local g = script.Parent

u.InputBegan:Connect(function(input, typing)
	if typing then return end

	if input.KeyCode == Enum.KeyCode.Tab then
		g.Visible = true
	end
end)

u.InputEnded:Connect(function(input, typing)
	if typing then return end

	if input.KeyCode == Enum.KeyCode.Tab then
		g.Visible = false
	end
end)
1 Like