Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Any way to make any hat on your head a certain color?

Asked by 8 years ago

i tried this it didnt work though

local Haircolor = Instance.new("NumberValue", stats) Haircolor.Name = "Haircolor"

math.rand(1,5)



if Haircolor.Value == 1 then Hat.BrickColor = BrickColor.new(Haircolor1) elseif Haircolor.Value == 2 then Hat.BrickColor = BrickColor.new(Haircolor2) elseif Haircolor.Value == 3 then Hat.BrickColor = BrickColor.new(Haircolor3) elseif Haircolor.Value == 4 then Hat.BrickColor = BrickColor.new(Haircolor4) elseif Haircolor.Value == 5 then Hat.BrickColor = BrickColor.new(Haircolor5)

1 answer

Log in to vote
0
Answered by
Unlimitus 120
8 years ago

OK, well first off, You don't need a NumberValue for this. You can just use a variable like so: local number = math.random(1, 5)

Second, Hats do not have a BrickColor value, their Handles do, though.

Third, and finally, you do not need an if/else statement for this case. You can use a table and the random number, which will make it a lot easier to add more colors in the future.

Here is the script re-written by myself:

local hat -- change this to the hat you want to change
local hairColors = {
    "Bright red",
    "Bright blue",
    "Bright green",
    "Bright yellow",
    "Black",
}
local randomNumber = math.random(1, #hairColors) -- Pick a random number between 1 and the number of hair colors there are.
local color = BrickColor.new(hairColors[randomNumber]).Color -- Get the RGB value of the BrickColor

hat.Handle.Mesh.VertexColor = Vector3.new(color.r, color.g, color.b) -- Set the color of the hat to the color

Note: this code hasn't been tested

Hope this helps!

Ad

Answer this question