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
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).
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
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
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.
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.
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