What do I need to do to make this script work, need help!

Hello.

I am trying to make a script that is suppose to convert grass terrain into Leafygrass whenever my lawnmower runs over it but it seems to not work. if anyone can help me fix this I’d very appreciate it!

image

Thanks

local mowerPart = game.Workspace.Lawnmower.Body.Model.mowerPart.Part
local GRASS_MATERIAL_COLOR = Enum.Material.Grass 
local LEAFY_GRASS_MATERIAL = Enum.Material.LeafyGrass
local MIN = Vector3.new(-20, -20, -20)
local MAX = Vector3.new(20, 20, 20)

-- Function to replace grass terrain with leafy grass
local function replaceGrassWithLeafyGrass()
	workspace.Terrain:ReplaceMaterial(Region3.new(MIN, MAX), 4, Enum.Material.Grass, LEAFY_GRASS_MATERIAL)
end

-- Main loop
while true do
	
	local cellPosition = workspace.Terrain:WorldToCell(Vector3.new(mowerPart.Position.X, mowerPart.Position.Y, mowerPart.Position.Z))

	
	local cellMaterialColor = workspace.Terrain:GetMaterialColor(Enum.Material.Grass)
	print(cellMaterialColor)

	-- Convert grass terrain to leafy grass
	if cellMaterialColor == GRASS_MATERIAL_COLOR then
		replaceGrassWithLeafyGrass()
	end

	wait(0.1)
end

Looks like the MIN and MAX values arent going to move with the lawnmower, so try this

(mowerPart.Position + MIN, mowerPart.Position + MAX)

Where would I put that part in the script?

Put it in the replaceGrassWithLeafyGrass function when you create the region3

Did that and it still didnt work

Any errors or it just didnt work? And the code should look like this

local function replaceGrassWithLeafyGrass()
	workspace.Terrain:ReplaceMaterial(Region3.new(mowerPart.Position + MIN, mowerpart.Position + MAX), 4, Enum.Material.Grass, LEAFY_GRASS_MATERIAL)
end

nope there was no errors it just didn’t work

is anybody here? I haven’t gotten a response in awhile