Trying to move a mesh with code

  1. Have you tried adding vector3.new (for your first reply)
  2. set the position breh
if hum.FloorMaterial == "Grass" then
	clone.Position = vector3.new(hrp.Position.X,hum.FloorMaterial.Position.Y + hum.FloorMaterial.Size.Y/2, hrp.Position.Z)
	clone.Oreintation= hum.FloorMaterial.Orientation
	clone.Parent = Workspace.somewhererandom
end
2 Likes

I cant believe you forgot the . :angry:

3 Likes

Wierdā€¦ They all teleport to 1 locationā€¦

2 Likes

May I see your code againā€¦

make sure x and z is hrp.Positionā€¦ and trying to think of any other problemsā€¦

2 Likes

Vector3 needs an uppercase >:(

Code:

local function plant()
	local clone = placingDirt:Clone()
	local hrp = tool.Parent.HumanoidRootPart
	local hum = hrp.Parent.Humanoid
	
	clone.Parent = game.Workspace.Spawn.Farming
	
	if hum.FloorMaterial == "Grass" then
		clone.Position = Vector3.new(hrp.Position.X,hum.FloorMaterial.Position.Y + hum.FloorMaterial.Size.Y/2, hrp.Position.Z)
		clone.Oreintation= hum.FloorMaterial.Orientation
		clone.Anchored = true
	else
		clone:Destroy()
	end

	print("farmed")
end

Edit1: Wait Iā€™m dumb I forgot the .Value
Edit2: Nvm still does not work
Edit3: I added a print statement and it prints the FloorMaterial as 1280 so I changed Grass to 1280 and it still does not work

1 Like

Humanoid.FloorMaterial is an Enum of Enum.Material. It does not have a position or orientation property.
You should raycast from the humanoid root partā€™s position to the same position but with a negative offset on the Y axis (in other words, pointing down).

Robloxā€™s tutorial on raycasting.

1 Like

My bad then, at least I also learned something new

better use the other replyā€™s solution lol

local leg = tool.Parent:FindFirstChild("Right Leg")

clone.Position = Vector3.new(hrp.Position.X, leg.Position.Y - (leg.Size.Y / 2), hrp.Position.Z)

seems like it works
robloxapp-20230726-1331264.wmv (1.4 MB)

1 Like

Ok I think I have a working raycast, but how do I check the material??? I only want to till the grass, not something else.

1 Like

like @MartimDev said,

so you can still use it to check the material.
robloxapp-20230726-1341450.wmv (2.4 MB)
yep works

Make sure you mark CloutBl0xā€™s reply as solution.

1 Like

But it does not work whenever I try to check for a materials properties. When I am standing on grass, it does not think it is grass and deletes the clone

1 Like
if hum.FloorMaterial == Enum.Material.Grass then

I thinkā€¦

1 Like

Could you give me more of your code? Iā€™ll clean it up and try to fix it if I can.

1 Like

I donā€™t have much ha ha I am working on a raycast:

local function plant()
	local clone = placingDirt:Clone()
	local hrp = tool.Parent.HumanoidRootPart
	local invis = hrp.InvisDirt
	local rayOrigin = Vector3.new(invis.Position.X, invis.Position.z, invis.Position.y)
	local rayDirection = Vector3.new( invis.Position.X, -0.001, invis.Position.Z)
	
	
	local raycastResult = workspace:Raycast(rayOrigin, rayDirection)
	
	
	clone.Parent = game.Workspace.Spawn.Farming
	
	

	print("farmed")
end
1 Like

Whatā€™s InvisDirt?

more chars needed

1 Like

It is the location of where I want the dirt to be. It is also where I am casting the raycast. I donā€™t know how to check the material of the ground under with the raycast thoughā€¦ I just welded this to the HumanoidRootPart so it follows the player wherever they go.

1 Like

This works. I adapted your code, it doesnā€™t use the best practices or the naming conventions I like.

function plant()
	local hrp = tool.Parent.HumanoidRootPart
	local hum = hrp.Parent.Humanoid
	
	local raycastParameters = RaycastParams.new()
	raycastParameters.FilterDescendantsInstances = {tool.Parent} -- List of things the ray should ignore (the character in this case)
	
	local raycastResult = workspace:Raycast(hrp.Position, Vector3.new(0, -6, 0), raycastParameters)
	if raycastResult ~= nil then
		if raycastResult.Instance == workspace.Terrain and raycastResult.Material == Enum.Material.Grass then
			local clone = placingDirt:Clone()
			clone.Position = raycastResult.Position - Vector3.new(0, clone.Size.Y / 2, 0) -- Since the position is usually at the center of the part, offset it by half its height so it goes in the ground
			clone.Parent = game.Workspace.Spawn.Farming
		end
	end
end

As you can see, RaycastResult has a Material property.

1 Like

but checking floorMaterial liturally works
robloxapp-20230726-1341450.wmv (2.4 MB)

1 Like

It does not work for me lol, I think its because Iā€™m using parts.

1 Like

works for partsā€¦
robloxapp-20230726-1346514.wmv (1.5 MB)
its grass not glass btw

1 Like

How does this not work then:

local function plant()
	local clone = placingDirt:Clone()
	local hrp = tool.Parent.HumanoidRootPart
	local hum = hrp.Parent.Humanoid
	
	clone.Parent = game.Workspace.Spawn.Farming
	
	if hum.FloorMaterial.Value == "Enum.Material.Grass " then
		clone.Position = Vector3.new(hrp.Position.X,hum.FloorMaterial.Position.Y + hum.FloorMaterial.Size.Y/2, hrp.Position.Z)
		clone.Anchored = true
	else
		clone:Destroy()
		print(hum.FloorMaterial)
	end

	print("farmed")
end
1 Like