Why isn't my Terrain:ReplaceMaterial working?

What I’m trying to do is to have a small part on a bottom of the vehicle that changes the terrain below
Basically just trying to make a lawnmower

But no matter which guide I follow or try to edit the code myself, but nothing has happened

This is what code looks like that I currently have

local WorkspaceService = game:GetService("Workspace")
local Mower = WorkspaceService.Mower

local Part1 = Mower.GrassCutter.Position 
local Part2 = Mower.GrassCutter.Position

WorkspaceService.Terrain:ReplaceMaterial(Region3.new(Part1,Part2), 4, Enum.Material.Grass, Enum.Material.Ground)

And a screenshot of where the part 1 and 2 are located
(The green boxes)
image

I am wondering why this is not working at all and anyone knows and fix

You need to put the WorkspaceService.Terrain:ReplaceMaterial(Region3.new(Part1,Part2), 4, Enum.Material.Grass, Enum.Material.Ground) in a loop so it will run more than once. Right now, your script runs it at the beginning, and then it ends. You can use something like while true do, or you can get more complicated and utilize the RunService.

Ok I have put a loop on it but still nothing

while true do
	if Character.Humanoid.SeatPart then -- If player is sitting in a seat 
		print ("Player sitting")
	
		WorkspaceService.Terrain:ReplaceMaterial(Region3.new(Part1,Part2), 4, Enum.Material.Grass, Enum.Material.Ground)

	end	
	task.wait()
end

It’s not giving me any errors so I honestly don’t know what’s wrong with it

The api doc says:


So your regions min and max needs to be divisible by 4… check the points covered by your two points, see the example they use in the api.

Also to get when humanoid sits in a seat use the GetPropertyChangedSignal on the occupant of the seat.

5 Likes

Thanks, was able to getting it working with some trial and error.

2 Likes