GUI Scripting Help - "Press Any Key to Start" menu

Hey guys and gals!

I’m creating a solo game, and I’ve gotten a lot done so far, but now I’d like to remake my main menu. The only issue is that I have no clue how to script. I’ve tried using Roblox’s Assistant feature, and even ChatGPT, but all of the outputs come with errors that I cannot solve. This is one of the responses I’ve received. The GUI just disappears and shows the black screen. It doesn’t fade or anything, and never shows the main menu.


local screenGuiStartingMenu = game.Players.LocalPlayer.PlayerGui:WaitForChild("StartingMenu")
local frameStartingMenu = screenGuiStartingMenu:WaitForChild("StartingMenuFrame")

local screenGuiBlackScreen = game.Players.LocalPlayer.PlayerGui:WaitForChild("BlackScreen")
local frameBlackScreen = screenGuiBlackScreen:WaitForChild("Frame")

local screenGuiMainMenu = game.Players.LocalPlayer.PlayerGui:WaitForChild("MainMenu")
local frameMainMenu = screenGuiMainMenu:WaitForChild("Menu")

local function fadeFrame(frame, targetTransparency, duration)
	local tweenInfo = TweenInfo.new(duration, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
	local tweenProperties = { BackgroundTransparency = targetTransparency }

	local tween = game.TweenService:Create(frame, tweenInfo, tweenProperties)
	tween:Play()
	tween:Wait()  -- Wait for the tween to complete before continuing
end

local function handleKeyPress()
	print("Key pressed")

	-- Disable the StartingMenu
	frameStartingMenu.Parent.Enabled = false

	-- Fade out StartingMenu to black over 2 seconds
	fadeFrame(frameStartingMenu, 1, 2)

	-- Wait for 2 seconds at full transparency
	wait(2)

	-- Enable MainMenu and fade from BlackScreen to MainMenu over 2 seconds
	frameMainMenu.Parent.Enabled = true
	fadeFrame(frameBlackScreen, 1, 0.5)  -- Fade to black over 0.5 seconds
	fadeFrame(frameMainMenu, 0, 2)        -- Fade from black to MainMenu over 2 seconds
end

game.Players.LocalPlayer:GetMouse().KeyDown:Connect(function(key)
	handleKeyPress()
end)

print("Script is running")

When you join the game, it takes you straight to the menu, where you can hit play and change settings, but I’d like to make a “Press Any Key to Start” kind of menu, with a transition to the menu.

Any other topics I’ve found seem to be outdated or not working.

Any help would be appreciated. Thanks!

2 Likes

Soooo what is the issue what you are facing?

1 Like

Here’s a script that runs code when any key is pressed. I included touch aswell since keys cannot be pressed on mobile.

local UserInputService = game:GetService("UserInputService")


local Function
Function = UserInputService.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.Keyboard or input.UserInputType == Enum.UserInputType.Touch then -- If the input is any key on a keyboard (or touch)
		Function:Disconnect()
		
		-- Do this when the key is pressed
		
	end
end)

3 Likes

To be honest, I don’t think that you even have to check for the UserInputType, and I think that it’s better to just leave the function there without the if statement so that it’s compatible with all types of platforms.

2 Likes

True, it just depends what you really want to achieve. If you only want key inputs then it works but yeah, if you want any input then just remove the if statement.

1 Like

The GUI just disappears and shows the black screen. It doesn’t fade or anything, and never shows the main menu.

Sorry, I should have added that to the original post, first time actually posting on the forum.

2 Likes

Ok, the problem is this line, tween:Wait() is not a thing.

tween:Wait()  -- Wait for the tween to complete before continuing

If you just replace it with this then it should work, hopefully. This will just wait until the tween is completed, pretty self explainatory

tween.Completed:Wait()

Also, next time you get an issue like this, check the output and provide what error that occured, if any. It helps.

1 Like

:man_facepalming: That makes sense. Thank you a lot!

I’ll keep that in mind next time.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.