So I want to loop through works getting all the colours of objects but if some objects have the same colour then I dont want to save the same colour twice how can I do that?
You need to save all of the printed colors to a table, and then every object you check you need to verify that the color is not already in the table.
I dont know how to do that though?
You can create a table like this
local colorTable = {}
You can add something to a table like this
table.insert(colorTable, color)
You can iterate over a table like this
local colorMatch = false
for i, v in ipairs(colorTable) do
if v == color then colorMatch = true end
end
print(colorMatch)
After that you would have an if
statement to check if colorMatch was true or not, and if it is then you would skip printing.
I still dont really get it ive never done anything like this before
Since I’m not really supposed to give you code, how about you show me what you have so far?
local sizex = 250
local sizez = 250
local terrainModel = Instance.new("Model")
terrainModel.Name = "ProceduralGeneration"
terrainModel.Parent = workspace
local Size = 25 / 3
function RollingHills()
local frequency = 10
local amplitude = 5
for x = -sizex, sizex do
for z = -sizez, sizez do
local y = (math.sin(x / frequency) + math.cos(z / frequency)) * amplitude / 2
math.random()
local p = Instance.new("Part")
p.Size = Vector3.new(Size, Size, Size)
p.CFrame = CFrame.new(x * Size, y * Size, z * Size)
p:Destroy()
local Ran = math.random(1, 100)
local Ran2 = math.random(1, 10)
local Ran3 = math.random(1, 100)
if Ran2 > 10 then
workspace.Terrain:FillBlock(p.CFrame, p.Size, Enum.Material.Grass)
else
workspace.Terrain:FillBlock(p.CFrame, p.Size, Enum.Material.LeafyGrass)
end
if Ran2 == 1 then
local tree = script.Tree:Clone()
tree.MeshPart.BrickColor = BrickColor.Random()
tree:SetPrimaryPartCFrame(p.CFrame + Vector3.new(0, tree.PrimaryPart.Size.Y / 1.25, 0))
tree.Parent = terrainModel
elseif Ran3 == 1 then
local lamp = script.Model:Clone()
lamp:SetPrimaryPartCFrame(p.CFrame + Vector3.new(0, p.Size.Y / 1.25, 0))
lamp.Parent = terrainModel
end
end
wait()
end
end
RollingHills()
Where does it need to go? I don’t see you printing a color anywhere.
I want to change the trees colors to different shades of green like is there a different way of doing that?
try setting the leaf Green value randomize so like color3.fromrgb(R,“random green value”,B)
But you don’t want any of the trees to have the same color? That’s a little bit of a costly/laggy procedure for a simple terrain generator.
What I suggest is finding a range of greens, probably in HSV, and use that. This is seriously off-track from just checking what has already been printed though.
MeshThing.Color = Color3.fromHSV(
math.random(75, 120)/360, -- Range of green colors, lower is yellower, higher is bluer.
math.random(50,80)/100, -- Range of saturation, lower is more bleached and higher is more vibrant.
math.random(40, 65)/100, -- Range of brightness, lower is blacker and higher is brighter.
)
Do you know how I can check whether there is a group of parts that are connected but not like a load of parts just a small group? I want to create a pond thing
Not without some form of constraint, such as color or material.