mcpField
R
roblox-gui

roblox-gui

github.com/flatbedjデザイン・UI058 回インストール6 週間前に更新
リポジトリ

roblox-gui について

Roblox GUI開発向けのリファレンススキルです。コンテナの選択、サイズと配置、レスポンシブレイアウト、アニメーションなどを扱い、画面内やワールド空間のUIを実装する開発者を対象とします。

主な機能

  1. 01ScreenGui、SurfaceGui、BillboardGuiの選択
  2. 02UDim2によるサイズと配置
  3. 03レスポンシブレイアウトの構築
  4. 04TweenServiceによるアニメーション
  5. 05リスポーン後のGUI維持設定

活用シーン

  1. 01画面HUDやメニューの作成
  2. 02パーツやキャラクターへのラベル配置
  3. 03モバイル画面に合わせたレイアウト

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/flatbedj/roblox-skills --skill roblox-gui

インストール後、Claude Code で/roblox-guiを入力して読み込まれたか確認します。

詳細

Roblox GUI リファレンス

ネイティブ Robux シンボル

画像アイコンの代わりに、テキストラベルやボタンでは Roblox のネイティブ Robux グリフを使用します:utf8.char(0xE002)(Luau の文字列エスケープ "\u{E002}" と同等です)。 グリフは価格と同じテキストオブジェクト内に置いてください。そうすることで、間隔、スケーリング、地域別価格の更新が一緒に適用されます。

GUI コンテナの種類

コンテナ親用途
ScreenGuiPlayerGuiHUD、メニュー、オーバーレイ — 常に画面に表示されます
SurfaceGuiBasePartパーツの表面に表示するワールド空間の UI(看板、画面)
BillboardGuiBasePart または Model3D 空間でパーツの上に浮かびます(ネームタグ、ヘルスバー)
ScreenGui
-- LocalScript in StarterGui or StarterPlayerScripts
local player = game:GetService("Players").LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")

local screenGui = Instance.new("ScreenGui")
screenGui.Name = "HUD"
screenGui.ResetOnSpawn = false   -- keep GUI across respawns
screenGui.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
screenGui.Parent = playerGui
SurfaceGui
local surfaceGui = Instance.new("SurfaceGui")
surfaceGui.Face = Enum.NormalId.Front
surfaceGui.SizingMode = Enum.SurfaceGuiSizingMode.PixelsPerStud
surfaceGui.PixelsPerStud = 50
surfaceGui.Parent = workspace.ScreenPart

local label = Instance.new("TextLabel")
label.Size = UDim2.fromScale(1, 1)
label.Text = "Hello World"
label.Parent = surfaceGui
BillboardGui
local billboard = Instance.new("BillboardGui")
billboard.Size = UDim2.fromOffset(200, 50)
billboard.StudsOffset = Vector3.new(0, 2.5, 0)  -- float above head
billboard.AlwaysOnTop = false
billboard.Parent = character:WaitForChild("Head")

local nameLabel = Instance.new("TextLabel")
nameLabel.Size = UDim2.fromScale(1, 1)
nameLabel.BackgroundTransparency = 1
nameLabel.Text = player.DisplayName
nameLabel.Parent = billboard

UDim2 によるサイズ設定と配置

UDim2.new(xScale, xOffset, yScale, yOffset) — スケールは親に対する 0~1 の値、オフセットはピクセル単位です。

frame.Size     = UDim2.new(1, 0, 0, 50)       -- full width, 50px tall
frame.Position = UDim2.new(0, 0, 0, 0)         -- top-left corner

frame.Size     = UDim2.fromScale(0.6, 0.4)     -- 60% wide, 40% tall
frame.Position = UDim2.new(0.2, 0, 0.3, 0)    -- centered (0.2 = (1-0.6)/2)

UDim2.fromScale(0.5, 0.5)    -- scale only
UDim2.fromOffset(300, 150)   -- pixels only

AnchorPoint は要素のピボットを移動します(各軸で 0~1):

frame.AnchorPoint = Vector2.new(0.5, 0.5)   -- pivot at center
frame.Position    = UDim2.fromScale(0.5, 0.5)  -- truly centered on screen

レスポンシブデザイン

あらゆる画面サイズに UI を適応させるため、オフセットよりスケールを優先します。

button.Size     = UDim2.fromScale(0.2, 0.07)
button.Position = UDim2.new(0.4, 0, 0.85, 0)

-- Prevent distortion with UIAspectRatioConstraint
local arc = Instance.new("UIAspectRatioConstraint")
arc.AspectRatio = 4   -- width:height = 4:1
arc.Parent = button

TweenService によるアニメーション

local TweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(0.3, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)

local menuFrame = script.Parent

local function openMenu()
    TweenService:Create(menuFrame, tweenInfo, {
        Position = UDim2.new(0.05, 0, 0.1, 0)
    }):Play()
end

local function closeMenu()
    TweenService:Create(menuFrame, tweenInfo, {
        Position = UDim2.new(-0.5, 0, 0.1, 0)
    }):Play()
end

-- Animated progress bar
local function setProgress(bar, pct)
    TweenService:Create(bar, TweenInfo.new(0.2), {
        Size = UDim2.new(pct, 0, 1, 0)
    }):Play()
end

LocalScript の配置

場所備考
StarterGui参加時に PlayerGui にクローンされます。維持するには ResetOnSpawn = false を使用します
StarterPlayerScripts1 回だけ実行され、リスポーン時にリセットされません。永続的なマネージャーに適しています
StarterCharacterScriptsスポーンのたびに再実行されます。キャラクターに依存する UI に適しています
-- Safe pattern: wait for character
local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

humanoid.HealthChanged:Connect(function(health)
    -- update health bar
end)

ResetOnSpawn

screenGui.ResetOnSpawn = false  -- persist across respawns (inventory, settings)
screenGui.ResetOnSpawn = true   -- re-create on respawn (respawn timer) — default

よく使うパターンのクイックリファレンス

パターン主な設定
全画面オーバーレイSize = UDim2.fromScale(1,1)、Position = UDim2.fromScale(0,0)
画面下部中央の HUD バーAnchorPoint = (0.5,1)、Position = UDim2.new(0.5,0,1,-10)
パディング付きリストFrame 内に UIPadding と UIListLayout を配置
スクロール可能なリストScrollingFrame と UIListLayout を使用し、UIListLayout.AbsoluteContentSize から CanvasSize を設定
角丸CornerRadius = UDim.new(0, 8) を設定した UICorner
拡大縮小するテキストTextLabel/TextButton で TextScaled = true にすると、コンテナに合わせてフォントが拡大します
動的なフレームの高さAutomaticSize = Enum.AutomaticSize.Y にすると、子要素に合わせてフレームが拡張されます
ヘルスバー入れ子のフレームを使用します。外側は背景、内側は Size.X.Scale による Tween で変化します
ネームタグHead に BillboardGui を配置し、StudsOffset = Vector3.new(0, 2.5, 0) に設定

よくある間違い

間違い修正方法
リスポーン時に GUI が消えるResetOnSpawn = false を設定するか、StarterPlayerScripts を使用します
モバイルで UI の表示が崩れるUDim2.fromScale と UIAspectRatioConstraint を使用します
スクリプトが PlayerGui を見つけられないplayer:WaitForChild("PlayerGui") を使用します
Tween が実行されないプロパティが Tween 対応か確認します。Text は非対応ですが、Position と Size は対応しています
BillboardGui が壁越しに表示されるAlwaysOnTop = false であることを確認します
最初のフレームで AbsoluteSize がゼロになるtask.defer 内、または最初のレンダリングステップ後に読み取ります
重なったフレームを通り抜けてクリックされる透明な入力ブロック用 Frame を追加するか、Modal = true に設定します
SurfaceGui がちらつくLightInfluence = 0 に設定し、パーツが薄すぎないことを確認します
モバイルでテキストが小さすぎるTextScaled = true に設定します。固定の TextSize は画面サイズに適応しません
モバイルで UI のテストが難しいStudio の デバイスエミュレーター(Test タブ → Device)を使ってレイアウトをプレビューします

コメント