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!
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