Reputation: 1
I'm making a ROBLOX game, and I've got a GUI issue:
I don't even want "Game Loading..." to show up, I only put it there when I was learning the ins and outs of buttons.
My GUI is just the start menu, so when you click Start Game, the GUI should go away and you'd be loaded into the actual game.
Here's what I've got for the script for the button:
local button = script.Parent
local toggled = false
local function onButtonActivated()
if toggled == false then
button.Text = "Game Loading..."
toggled = true
else
button.Text = "Start Game"
toggled = false
end
end
button.Activated:Connect(onButtonActivated)
Note: I'm using Lua (ROBLOX's default language) via IntelliJ and just copy-pasting my finished code into the scripts, since IntelliJ has a much better text editor than ROBLOX's default one.
Upvotes: 0
Views: 420
Reputation:
local button = script.Parent
local guiObj = --a reference to the main screengui which the button is a descendant of
local function onButtonClicked()
guiObj:Destroy()
end
button.MouseButton1Click:Connect(onButtonClicked)
You could do some fancy fading and stuff if you want to.
Upvotes: 0
Reputation: 40
If this place is just a hub with the start menu, and the actual game is elsewhere in the universe, then you'll need to use TeleportService:Teleport()
to move the LocalPlayer
to that game. After the teleport is done, the player would be able to play that game with no issues. Here's an example using your code sample:
local button = script.Parent
local toggled = false
local destination = 0 -- Change 0 to the place ID you want the user to be teleported to
local TeleportService = game:GetService("TeleportService")
local function onButtonActivated()
if toggled == false then
button.Text = "Game Loading..."
--toggled = true
TeleportService:Teleport(destination)
else
button.Text = "Start Game"
toggled = false
end
end
button.Activated:Connect(onButtonActivated)
However, if you're loading this GUI inside of the actual game, all you need to do is :Destroy()
the GUI object. This will permenantly move the GUI object and all of its children under nil
, and disconnect all connections.
In the game, this will mean that the GUI simply disappears, and the player will be able to continue playing the game. Unless you have other critical code running inside the GUI, this should be the go-to solution if you're working with just one place.
local button = script.Parent
local toggled = false
local guiObj = nil -- Replace nil with a reference to the "ScreenGui/BillboardGUI" object that houses the 'button'.
local function onButtonActivated()
if toggled == false then
--[[button.Text = "Game Loading..."
toggled = true]]--
guiObj:Destroy()
else
button.Text = "Start Game"
toggled = false
end
end
button.Activated:Connect(onButtonActivated)
Upvotes: 0