Main Menu Play Button Help

I am trying to make a main menu for my game. How would I make the player spawn in when they click play?

3 Likes

:LoadCharacter() seems like the best answer to loading in the character when the user presses play

2 Likes

You would also want the GUI to disappear so add a localscript into play and write a script that makes the main menu disappear when the player clicks it

1 Like

You really wouldn’t want 20 different scripts in a gui controlling each gui element, not only would it be messy but it would also be somewhat hard to maintain

I have that already, but thanks

Okay that seems likw it would work how would I add that to my current script:

``local play = script.Parent
local main = script.Parent.Parent.Parent

play.MouseButton1Click:Connect(function()
main.Enabled = false
end)``

Since :LoadCharacter() is only available on server, you’d want to setup a secured RemoteEvent that loads the player’s character when it’s fired

I am kinda new at this programming stuff, i dont understand how those work…

Basically, a RemoteEvent has three main functions:
:FireServer() used to send data from the client to the server
:FireClient() used to send data from the server to a specific client
:FireAllClients() used to send data to all clients on the server

:FireServer() forces the first argument to be the player which called the function

If you don’t want a game with easily exploitable RemoteEvents then you’d want to add sanity checks on the server,

for example, a buy item event:
A client sends data to the server, notifiying it that the client wants to buy something, let’s say a shovel, the server checks if the user has enough money to buy the shovel,

if the requirement is met, the server gives the client the item they want to buy and tells the client that the purchase was successful.

And if the requirement isn’t met, the server notifies the client that they do not have enough money to buy the shovel.

Okay, how would I add the RemoteEvent to my script?

On the client:

Add a RemoteEvent to ReplicatedStorage, then call :FireServer() on the RemoteEvent in the play button’s code,

On the server:

Connect a function to .OnServerEvent with some sanity checks, to make sure that a client doesn’t attempt to, for example, respawn every player in the server with 1 click.

Roblox has a article on DevHub which goes more in depth on how to use RemoteEvents, and it probably explains them better than me.

so
``local play = script.Parent
local main = script.Parent.Parent.Parent

play.MouseButton1Click:Connect(function()
main.Enabled = false
end)
:FireServer()``
?

Not just :FireServer, you’d want to do something like this:

game.ReplicatedStorage.LoadCharacter:FireServer()

Also for the love of god, use codeblocks!

how do use code blocks?? Help…

Add 3 ` at the top of the code and on the bottom of the code

or use the image button while having the code highlighted

ok. So the final code is: local play = script.Parent
local main = script.Parent.Parent.Parent

play.MouseButton1Click:Connect(function()
	main.Enabled = false
end)
game.ReplicatedStorage.LoadCharacter:FireServer()

??

Put game.ReplicatedStorage.LoadCharacter:FireServer() inside

not outside of it

local play = script.Parent
local main = script.Parent.Parent.Parent

play.MouseButton1Click:Connect(function()
	main.Enabled = false
game.ReplicatedStorage.LoadCharacter:FireServer()
end)

Yep, just like that, it should be as easy as 123 on the server if you know what you’re doing.

okay so after I put in this code and the RemoteEvent, is there a script I have to put into the Event??

Sorry if i am wasting your time