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

How to Change Rotation and Color... continued?[SOLVED BY DevFrank]

Asked by 9 years ago

I have finally figured out how to change rotation on enter and now I need a script to also change color.

local leaf = game.Workspace.Leaf

game.Players.PlayerAdded:connect(function()
    leaf.CFrame = CFrame.new(leaf.CFrame.x, leaf.CFrame.y, leaf.CFrame.z) * CFrame.Angles(math.random(), math.random(), math.random())
    leaf.BrickColor = "Sand Green" or "Medium Green" or "Bright Green" or "Pastel Green" 
end)

2 answers

Log in to vote
2
Answered by 9 years ago

You should use a table of colors and then use :BrickColor.new(), Then you make math.random() choose one of the colors in the table. This way is more sufficient. This method can be used for random maps items and more.

If you don't understand then there are some links below to the wiki.

local leaf = game.Workspace.Leaf
local leaf_colors = {"Pastel Green", "Bright Green", "Medium Green", "Sand Green"}

game.Players.PlayerAdded:connect(function()
leaf.CFrame = CFrame.new(leaf.CFrame.x, leaf.CFrame.y, leaf.CFrame.z) * CFrame.Angles(math.random(), math.random(), math.random())
    leaf.BrickColor = BrickColor.new(leaf_colors[math.random(1, #leaf_colors)])
end)

http://wiki.roblox.com/index.php?title=Table

http://wiki.roblox.com/index.php?title=Random_numbers

RoboFrog's Answer with RGB, You need to change it. You must replace R, G, B with numbers that range from0 - 255. I hope that makes that more clear.

leaf.BrickColor = BrickColor.new(R/255, G/255, B/255) 

Don't forget to mark this as solved and as the correct answer!

Ad
Log in to vote
1
Answered by
RoboFrog 400 Moderation Voter
9 years ago

Heh, back for round 2 I see. This is a bit more difficult than your first question, but I'll do my best to help you answer it.

In this case, the use of or is not correct. It won't know how to choose one or the other, all it knows is that they're all choices. Instead, you'll want to use a randomizing system --

local num = math.random(2)
if num == 1 then
    leaf.BrickColor = BrickColor.new("Sand Green")
elseif num == 2 then
    leaf.BrickColor = BrickColor.new("Medium Green")
end

This picks a random whole number between 1 and 2, and then changes the BrickColor of the block.

You also need to add the = BrickColor.new() piece, or else it won't know how to set the color.

As a bonus, you can also set the colors to non-ROBLOX colors. You can use a site such as this and use the R, G, and B ccomponents (in that order) to select your colors. Just use this format instead of ("Medium Green") --

leaf.BrickColor = BrickColor.new(R/255, G/255, B/255)
0
Well RoboFrog. It works alright. But one problem.. It changes the color yes it does. It changes the color to Light Stone Gray... raystriker6707 30 — 9y
1
That's quite strange, I don't see why it's doing that. I would go with DevFrank's answer then, since a table is likely a better answer (unless you want weighted choices, in which case I could find the issue). RoboFrog 400 — 9y

Answer this question