Empty
Empty
Empty
StarterGui 是 Roblox 中的一個服務,它保存了 GUI (圖形用戶界面) 元素,當玩家加入遊戲時,這些元素會被複製到每個玩家的 PlayerGui 中。
Empty
Empty
Empty
放置在 StarterGui 中的腳本通常控制 UI 元素,例如按鈕、菜單和其他在遊戲過程中玩家與之交互的界面元素。
StarterGui 示例
Empty
Empty
Empty
-- StarterGui > HealthGui > HealthScript
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local healthGui = script.Parent
local healthBar = healthGui:WaitForChild("Frame")
local healthLabel = healthBar:WaitForChild("TextLabel")
local function updateHealth()
local humanoid = character:FindFirstChildOfClass("Humanoid")
if humanoid then
local healthPercent = humanoid.Health / humanoid.MaxHealth
healthBar.Size = UDim2.new(healthPercent, 0, 1, 0)
healthLabel.Text = math.ceil(humanoid.Health) .. " / " .. math.ceil(humanoid.MaxHealth)
end
end
local humanoid = character:WaitForChild("Humanoid")
humanoid.HealthChanged:Connect(updateHealth)
updateHealth()
Roblox Studio