ROBLOX Lua - 尽管脚本中有不同的颜色id,仍然给玩家错误的等级颜色

嘿,伙计们,我制作了一个在游戏中可以看到的等级GUI系统。

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

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

player.CharacterAdded:Connect(function(character)

    if player:IsInGroup(4348965) then -- 将数字设置为您的组ID!
        local clonedgui = billboardgui:Clone()
        clonedgui.TextLabel.Text = "组成员"
        clonedgui.TextLabel.TextColor3 = Color3.fromRGB(36,154,136)
        clonedgui.Parent = game.Workspace:WaitForChild(player.Name).Head -- 是的,您还可以只说character.Head
    end

    if player.Name == "RealFancySmash" then -- 更改为您的名称或他人的名称!
        if character.Head:FindFirstChild("BillboardGui") then
            character.Head.BillboardGui.TextLabel.Text = "游戏创作者"
        else
            local clonedgui = billboardgui:Clone()
            clonedgui.TextLabel.Text = "游戏创作者"
            clonedgui.TextLabel.TextColor3 = Color3.fromRGB(255,255,255)
            clonedgui.Parent = game.Workspace:WaitForChild(player.Name).Head -- 是的,您还可以只说character.Head
        end
    end

end)

end)

所以基本上,脚本的第一部分赋予组成员“组成员”等级,而脚本的第二部分赋予我“游戏创作者”的等级。我遇到的问题是,“游戏创作者”的等级接收与“组成员”等级相同的颜色(36,154,136),尽管被设置为白色(255,255,255)。我应该得到一个白色的“游戏创作者”的等级,而不是“组成员”等级的青色。谢谢!非常感谢任何帮助!

点赞
用户5373986
用户5373986

你的问题似乎在于代码无法到达会将你的颜色变为白色的else部分。我会在下面为您详细讲解发生了什么,这样您就可以了解出了什么问题(或者您也可以直接跳到底部)。

if player:IsInGroup(4348965) then

首先,代码检查玩家是否在您的团队中。由于您作为所有者是该团队的一部分,因此该代码部分运行将广告牌克隆到您玩家的头上,并将所有颜色和文本设置为团队成员的颜色和文本。

if player.Name == "RealFancySmash" then

然后,它到达第二个if检查。这是您的名字,因此代码运行到第三个if检查。

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

现在,由于您之前已经将广告牌克隆到了您的头上,因此此if返回true并执行其下面的代码。由于它返回true,代码将不会激活else部分。

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

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

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

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

2018-08-20 17:03:16