ROBLOX Lua-尽管脚本中的颜色ID不同,但给玩家错误的等级颜色

时间:2018-08-17 19:03:28

标签: lua title roblox

伙计们,所以我制作了一个Rank GUI系统,可以在游戏中被玩家看到。

local billboardgui = 
game:GetService("ServerStorage"):WaitForChild("BillboardGui")

game.Players.PlayerAdded:Connect(function(player)

player.CharacterAdded:Connect(function(character)

    if player:IsInGroup(4348965) then -- Set the number to your group ID !
        local clonedgui = billboardgui:Clone()
        clonedgui.TextLabel.Text = "Group member"
        clonedgui.TextLabel.TextColor3 = Color3.fromRGB(36,154,136)
        clonedgui.Parent = game.Workspace:WaitForChild(player.Name).Head -- Yes, you can also just say character.Head                    
    end        

    if player.Name == "RealFancySmash" then -- Change to your name or someone else's!        
        if character.Head:FindFirstChild("BillboardGui") then
            character.Head.BillboardGui.TextLabel.Text = "Game Creator"
        else                
            local clonedgui = billboardgui:Clone()
            clonedgui.TextLabel.Text = "Game Creator"
            clonedgui.TextLabel.TextColor3 = Color3.fromRGB(255,255,255)
            clonedgui.Parent = game.Workspace:WaitForChild(player.Name).Head -- Yes, you can also just say character.Head                    
        end
    end

end)



end)

因此,基本上,脚本的第一部分为组成员提供“组成员”等级,而脚本的第二部分为我提供“游戏创建者”级。我遇到的问题是“游戏创建者”等级获得的颜色(36,154,136)与“组成员颜色”设置为白色(255,255,255)相同。我应该得到一个白色的“ Game Creator”等级,而不是“ Group Member”等级中的青色。谢谢!任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:0)

您的问题似乎是代码没有到达else部分,这会使您的颜色变成白色。我将向您介绍下面发生的事情,以便您可以了解出了什么问题(或者我可以跳到最底端)。

if player:IsInGroup(4348965) then

首先,代码正在检查播放器是否在您的组中。您作为所有者是该组的一部分,因此本节代码将克隆广告牌至玩家头,并将所有颜色和文本设置为组成员的颜色。

if player.Name == "RealFancySmash" then

然后进入第二个if检查。这是您的名字,因此如果选中,代码将运行到第三个。

if character.Head:FindFirstChild("BillboardGui") then

现在,由于您早先已经将广告牌克隆到您的头部,如果执行下面的部分返回true,则可以这样做。返回true时,代码将不会激活else部分。

clonedgui.TextLabel.TextColor3 = Color3.fromRGB(255, 255, 255)

如果您在下面插入此行代码,

character.Head.BillboardGui.TextLabel.Text = "Game Creator"

您会发现,由于现在正在执行颜色更改,因此您的角色广告牌是正确的颜色,希望这对您学习Lua也有所帮助。