[英]How can I load my workspace from my start menu GUI in ROBLOX?
I'm making a ROBLOX game, and I've got a GUI issue:我正在制作 ROBLOX 游戏,但我遇到了 GUI 问题:
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.我的 GUI 只是开始菜单,所以当您单击开始游戏时,GUI 应该 go 消失,您将被加载到实际游戏中。
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.注意:我通过 IntelliJ 使用 Lua(ROBLOX 的默认语言)并将完成的代码复制粘贴到脚本中,因为 IntelliJ 的文本编辑器比 ROBLOX 的默认编辑器好得多。
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.如果这个地方只是一个带有开始菜单的中心,而实际游戏在宇宙的其他地方,那么您需要使用TeleportService:Teleport()
将LocalPlayer
移动到该游戏。 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.但是,如果您在实际游戏中加载此 GUI,您需要做的就是:Destroy()
GUI object。 This will permenantly move the GUI object and all of its children under nil
, and disconnect all connections.这将永久地将 GUI object 及其所有子级移动到nil
下,并断开所有连接。
In the game, this will mean that the GUI simply disappears, and the player will be able to continue playing the game.在游戏中,这意味着 GUI 会消失,玩家可以继续玩游戏。 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.除非您在 GUI 中运行其他关键代码,否则如果您只在一个地方工作,这应该是首选解决方案。
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)
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.如果你愿意,你可以做一些花哨的褪色和东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.