How I can paint terrain using script?

Or add, sorry (30 characterssss)

But how? How you want me to do it? Using the :FillBlock() Method?

I tried to do it with :FillBlock() but it fills instead of replacing.

I do believe that’s how it works. I didn’t even know that scripts could edit terrain at all. Try something like this:

if whatevervariable then
Terrain location that you want:FillBlock()

Oh, never mind. You should try something like this:

if whatevervariable then
Terrain location that you want.TerrainType = dirt

There could be 5 million errors in that script, I have no idea. I hope it helped tho.

You could try using :FillRegion() instead.

How I could use it in this situation?

Oh wait actually nevermind, The only way is changing the material of it or changing the color of the material.

So how terrain tools’s paint feature works then?

It switches a material with other… (I think I still didnt understand your question)

Here I explained what I wanted to do.

Oh wait I think I found the solution for this.

Go down to the Functions and there will have ReplaceMaterial.

1 Like

You can see how Roblox does it, check their GitHub:

1 Like

Ok, thank you.

workspace.Terrain:ReplaceMaterial(Region3.new(min, max), 4, materialToReplace, replacementMaterial)

One more question, how I create Region3.new() with size and position?

Yes the function is here:

Actually you dont need to do Size and Position, Region3.new() returns a region from the minimum to the maximum

Let’s say there is a point at 0,0,0 and other at 10,10,10. When you create a Region3.new() that has the 0,0,0 at minimum and 10,10,10 as maximum it will create a region that is inside that.

Meaning that it has a size and stays at the position between these.

I still don’t understand, could you provide an example on how I could create Region3.new() to where part is located at?

part.Position and part.Size -> Region3.new()

local region = Region3.new(part.Position)
region:ExpandToGrid(-part.Size)

(Whoops this was innacurate)

Here is how you could do it:

local region = Region3.new(part.Position, part.Size)
region:ExpandToGrid(4)

it just returns Region cannot be empty. Well this persons answer fixed my problem.

hey, ik its a little late but, its actually pretty easy, but if you want the part to be rotated you will have to use EgoMoose module.

this will create a region3 from a partm this doesnt support rotation. because for rotating regions you need a lot of work . or just egomoose module witch is really easy to use.

2 Likes