I have this overhead gui which shows the players level, I want the textcolor of the players level to change depending on the players level.
This is what I have so far:
local Colours = {
{1, Color3.fromRGB(255, 0, 0)},
{100, Color3.fromRGB(255, 150, 0)},
{200, Color3.fromRGB(255, 255, 0)},
{300, Color3.fromRGB(0, 255, 0)},
{500, Color3.fromRGB(0, 0, 255)},
{700, Color3.fromRGB(125, 0, 255)},
}
table.sort(Colours, function(a, b) -- Puts table in order
return a[1] < b[1]
end)
for i, Colour in pairs(Colours) do
if PlayerLevel <= Colour[1] and PlayerLevel > Colours[i + 1][1] then
Level.TextColor3 = Colour[2]
wait(1)
end
end
It gives me this error: attempt to index nil with number
I dont know what is wrong and if this is the correct way to do it.
what I THINK you are trying to do is check if player is within a level range like level 1 - 99, 100 - 200.
so i think this will do it. Replace the if statement in the for loop with this
if PlayerLevel >= Colour[1] and (i == #Colours or PlayerLevel < Colours[i + 1][1])
What this will do is check if the PlayerLevel is greater than or equal to the level of the Colour, and checks if the PlayerLevel is less than the level of the next colour.
I added this, because let’s say you are already at the last colour, you will check if the PlayerLevel is greater than that but lesser than the next Colour, however there is no next colour so we will check if that is the last/highest color. This part should be before
because, it will check First if it is the last colour, before checking the next colour or else it will error