如何制作 Roblox UI
发布: (2026年1月16日 GMT+8 09:15)
3 min read
原文: Dev.to
Source: Dev.to
第一步:创建 UI
- 打开 Roblox Studio。
- 在 Explorer 中,找到 StarterGui。
- 插入一个 ScreenGui 并将其重命名为
MainMenuGui。 - 在
MainMenuGui内,插入一个 Frame 并将其重命名为MainFrame。 - 在
MainFrame内,插入:- 一个名为
Title的 TextLabel。 - 一个名为
PlayButton的 TextButton。
- 一个名为
此时,如果在 Studio 中点击 Play,你应该能看到菜单。
UI 设置
MainFrame
- Size:
{1, 0}, {1, 0} - BackgroundColor3: 深灰色(或你喜欢的任何颜色)
- BorderSizePixel:
0
Title
- Text:
MY GAME - TextScaled:
true - Size:
{0.6, 0}, {0.2, 0} - Position:
{0.2, 0}, {0.15, 0} - BackgroundTransparency:
1
PlayButton
- Text:
PLAY - TextScaled:
true - Size:
{0.3, 0}, {0.12, 0} - Position:
{0.35, 0}, {0.5, 0}
第二步:主菜单脚本
- 在
MainMenuGui中插入一个 LocalScript。
脚本代码
local player = game.Players.LocalPlayer
local gui = script.Parent
local mainFrame = gui:WaitForChild("MainFrame")
local playButton = mainFrame:WaitForChild("PlayButton")
playButton.MouseButton1Click:Connect(function()
mainFrame.Visible = false
print("Game Started")
end)
脚本工作原理
- LocalScripts 在玩家的电脑上运行,这是 UI 所必需的。
script.Parent指向ScreenGui。WaitForChild确保在访问之前 UI 元素已经存在。MouseButton1Click在按钮被点击时触发。- 将
Visible设为false会立即隐藏菜单。
没有技巧,也没有魔法。
第三步:在点击 Play 之前锁定玩家(可选)
如果你希望玩家在点击 Play 之前无法移动,请按以下步骤操作:
- 前往 StarterPlayer → StarterPlayerScripts。
- 插入一个 LocalScript。
脚本代码
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
humanoid.WalkSpeed = 0
humanoid.JumpPower = 0
local gui = player.PlayerGui:WaitForChild("MainMenuGui")
local frame = gui:WaitForChild("MainFrame")
frame:GetPropertyChangedSignal("Visible"):Wait()
humanoid.WalkSpeed = 16
humanoid.JumpPower = 50
脚本的作用
- 玩家生成。
- 通过将
WalkSpeed和JumpPower设置为0来禁用移动。 - 脚本等待菜单框架变为不可见。
- 一旦点击 Play(框架隐藏),移动功能恢复(
WalkSpeed = 16,JumpPower = 50)。
这是一套非常标准的 Roblox 设置。