プレイヤーキャラの上に階級などを表示するプログラムです。

local Players = game:GetService("Players")

-- プレイヤーがキャラクターを持ったときに階級を表示する
Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        -- BillboardGuiを作成
        local billboardGui = Instance.new("BillboardGui")
        billboardGui.Size = UDim2.new(4, 0, 1, 0) -- サイズ調整
        billboardGui.StudsOffset = Vector3.new(0, 3, 0) -- キャラクターの頭の上に表示
        billboardGui.AlwaysOnTop = true

        -- TextLabelを作成して階級を表示
        local textLabel = Instance.new("TextLabel", billboardGui)
        textLabel.Size = UDim2.new(1, 0, 1, 0)
        textLabel.BackgroundTransparency = 1
        textLabel.TextColor3 = Color3.new(1, 1, 1) -- 白色
        textLabel.TextStrokeTransparency = 0.5 -- 縁取りを追加して読みやすくする
        textLabel.TextScaled = true -- テキストサイズを自動調整
        textLabel.Font = Enum.Font.SourceSansBold

        -- 階級を取得してTextLabelに表示
        local rank = getRankForPlayer(player) -- プレイヤーの階級を取得する関数を用意
        textLabel.Text = rank

        -- HeadパーツにBillboardGuiをアタッチ
        local head = character:WaitForChild("Head")
        billboardGui.Parent = head
    end)
end)

-- サンプル: プレイヤーの階級を取得する関数(必要に応じて実装)
local function getRankForPlayer(player)
    -- 例として、プレイヤーの勝利数に応じて階級を返す
    local wins = player:GetAttribute("Wins") or 0
    if wins >= 100 then
        return "Captain"
    elseif wins >= 50 then
        return "Commander"
    else
        return "Seaman"
    end
end

By schilverberch

ROBLOXでゲームを作ろう! 一緒にプログラミングを学びましょう。

5 thoughts on “プレイヤーの上に文字を表示”
    1. 以下のような感じのプログラムで出来ると思います。
      こちらは、ChatGPTのGPTsである「ロブロックス先生」が作って入れたものです。
      「ロブロックス先生」は以下のURLから使用できますのでご活用ください。
      https://chat.openai.com/g/g-koM7AR3zh-roburotukusuxian-sheng

      local part = script.Parent
      local clickDetector = part:FindFirstChild(“ClickDetector”)
      local gamePassID = 12345678 — ← ここを自分のGamePass IDに変えてね!

      clickDetector.MouseClick:Connect(function(player)
      if not player:HasPass(gamePassID) then
      game:GetService(“MarketplaceService”):PromptGamePassPurchase(player, gamePassID)
      end
      end)

      あと「有料アイテムの作り方」も参考にしてください。
      https://roblox-jp.com/reference/billing/

コメントを残す