在roblox studio中在玩家头部上方显示字母

我想让可以从 textlabel 上方看到文本,只有当他们有正确的团队等级(Captain)时,他们才能看到RedTeam 命名的团队的颜色 红色。 我该如何实现此目标?

以下是我的尝试:

    local Players = game:GetService("Players")
    local Teams = game:GetService("Teams")

    game.Players.PlayerAdded:Connect(function(player)
        player.CharacterAdded:Connect(function(character)
            game.Teams.Redteam.PlayerAdded:Connect(function(player)
                script.BillboardGui.Frame.Visible = true
                print(player.Name .. " 加入了游戏!")
                local groupId = "Captain"
                local guiClone = script.BillboardGui:Clone()
                guiClone.Parent = character.Head

                local textlabel = guiClone.Frame.TextLabel
                local groupRank = player:GetRoleInGroup(groupId)
                textlabel.Text = groupRank
            end)
        end)
    end)
点赞
用户12637568
用户12637568

在:GetRoleInGroup()中传递的groupid必须是与组相关的数字ID,而不是字符串。此函数返回用户的等级作为字符串。

local Players = game:GetService("Players")
local Teams = game:GetService("Teams")

-- Playerjoined是不必要的;当玩家进入团队时,正在执行同样的操作。
Teams.Redteam.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        -- 仅将框架设置为在资源管理器中可见。它作为脚本的父级,因此不需要下一行。
        --script.BillboardGui.Frame.Visible = true
        print(player.Name .. "加入了游戏!")

        local groupId = 123456789 -- 你的组ID
        local requiredRank = "Captain"
        local groupRank = player:GetRoleInGroup(groupId)

        if groupRank == requiredRank then
            local guiClone = script.BillboardGui:Clone()
            local textlabel = guiClone.Frame.TextLabel

            textlabel.Text = requiredRank

            guiClone.Parent = character:FindFirstChild("Head")
        end
    end)
end)
2021-02-02 02:09:09