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