【问题标题】:Display letters above the player head in roblox studio在 roblox studio 中显示玩家头部上方的字母
【发布时间】:2021-04-15 04:48:49
【问题描述】:

我想让玩家在第一次加入名为RedTeam 的团队时看到来自textlabel 的文字,团队颜色为Really Red,前提是他们具有正确的组排名(队长)。我怎样才能做到这一点?

这是我尝试过的:

    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 .. " joined the game!")
                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)

【问题讨论】:

    标签: lua roblox


    【解决方案1】:

    通过 :GetRoleInGroup() 传递的 groupid 必须是绑定到组的数字 id,而不是字符串。通过此函数返回用户的排名作为字符串。

    local Players = game:GetService("Players")
    local Teams = game:GetService("Teams")
    
    -- Playerjoined is unnecessary; the same thing is being done when a player enters the team.
    Teams.Redteam.PlayerAdded:Connect(function(player)
        player.CharacterAdded:Connect(function(character)
            -- Merely set the frame to be visible in explorer. Parented inside a script, it is not rendered, therefore the next line is not needed.
            --script.BillboardGui.Frame.Visible = true
            print(player.Name .. " joined the game!")
            
            local groupId = 123456789 -- Your group's 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-10-17
      • 2018-10-26
      • 2022-12-19
      • 2019-05-02
      • 2022-10-05
      • 1970-01-01
      • 2015-05-17
      • 2018-12-16
      • 2019-06-26
      相关资源
      最近更新 更多