RayCasting would be a better but more difficult way.
Try this:
local function plant()
local clonedDirt = placingDirt:Clone()
local humRootPart = tool.Parent.HumanoidRootPart
local rightLeg = humRootPart.Parent:FindFirstChild("Right Leg")
local targetX = humRootPart.Position.X
local targetY = (rightLeg.Position.Y - (rightLeg.Size.Y / 2))
local targetZ = humRootPart.Position.Z
clonedDirt.Position = Vector3.new(targetX, targetY, targetZ)
print(player.Name .. " farmed dirt.")
end
yes, previously we used your code to figure out the positions already, he was having trouble earlier since he forgot Vector3.new() which wasn’t in your reply earlier.
Here’s a full version of his script (i missed a bit)
local tool = script.Parent
local dirtFolder = workspace -- replace with where you want to store placed dirt
local serverStorage = game:GetService("ServerStorage")
local placingDirt = serverStorage:FindFirstChild("Part") -- replace part with your dirt's name
local function plant(player, character)
local clonedDirt = placingDirt:Clone()
local humRootPart = character:FindFirstChild("HumanoidRootPart")
local humanoid = character:FindFirstChild("Humanoid")
local rightLeg = character:FindFirstChild("Right Leg")
if humanoid.FloorMaterial == Enum.Material.Grass then
local targetX = humRootPart.Position.X
local targetY = (rightLeg.Position.Y - (rightLeg.Size.Y / 2))
local targetZ = humRootPart.Position.Z
clonedDirt.Position = Vector3.new(targetX, targetY, targetZ)
clonedDirt.Parent = dirtFolder
print(player.Name .. " farmed dirt.")
else
print(player.Name .. " wasn't on grass.")
end
end
tool.Activated:Connect(function()
local character = tool.Parent
local player = game.Players:GetPlayerFromCharacter(character)
plant(player, character)
end)
This works perfectly for me, the only reason it shouldn’t is because you’re on R15. If you are on R15, let me know so I can fix it.
The thing by @MartimDev works, but the thing we were working on does not work. I tried to do your approach, but it still does not work for some reason.