[英]How can I load my workspace from my start menu GUI in ROBLOX?
我正在制作 ROBLOX 游戲,但我遇到了 GUI 問題:
我什至不希望“游戲加載...”出現,我只是在學習按鈕的來龍去脈時才放在那里。
我的 GUI 只是開始菜單,所以當您單擊開始游戲時,GUI 應該 go 消失,您將被加載到實際游戲中。
這是我為按鈕編寫的腳本:
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)
注意:我通過 IntelliJ 使用 Lua(ROBLOX 的默認語言)並將完成的代碼復制粘貼到腳本中,因為 IntelliJ 的文本編輯器比 ROBLOX 的默認編輯器好得多。
如果這個地方只是一個帶有開始菜單的中心,而實際游戲在宇宙的其他地方,那么您需要使用TeleportService:Teleport()
將LocalPlayer
移動到該游戲。 傳送完成后,玩家將能夠毫無問題地玩該游戲。 這是使用您的代碼示例的示例:
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)
但是,如果您在實際游戲中加載此 GUI,您需要做的就是:Destroy()
GUI object。 這將永久地將 GUI object 及其所有子級移動到nil
下,並斷開所有連接。
在游戲中,這意味着 GUI 會消失,玩家可以繼續玩游戲。 除非您在 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)
如果你願意,你可以做一些花哨的褪色和東西。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.