Trying to move a mesh with code

It always tilts because it can’t be inside of another part, but only when I make another dirt too close to it.

Is it anchored?

chars i need them please

Always tilt = change pivot orientation

pivot is a property

Yep

charssssssssssssssssssssss

The problem is I don’t want it inside of other dirt…

Would you consider using a mouse placing system instead? It would be much easier to combat these problems.

image
This shows with the problem and without

I mean I would need to change a system that works completely fine by itself otherwise, so if I can, I would like to use this system

Alright.

Are your current bugs the part rotation and the fact that you can place on existing dirt?

Yep I think thats what you mean

Currently working on fixing and polishing it.

It will be a combination of the RayCast solution and mine.

It might be a while since I’ll probably eat dinner in like 10 minutes.

UPDATE: I’m overcomplicating it, kind of.

It’s gonna be very polished, like finished polished.

Alright. It’s done.

It’s very long and semi-organized. I’ve added comments on some features that you might want to change.

local tool = script.Parent
local dirtFolder = workspace.DirtParts -- replace with where you want to store placed dirt
local showRegions = false -- if you want regions to show, enable this

-----

local placingOnCooldown = false -- this is the place cooldown, don't touch

-----

local placingDirt = game.ServerStorage:FindFirstChild("Dirt") -- replace dirt with your dirt's name
local defaultDirtRotation = placingDirt.Orientation
placingDirt.Anchored = true
placingDirt.CanCollide = false -- this can be true if you want

-----

local function placeRegion(searchRegion, chosenPosition)
	
	local regionSize = searchRegion.Size
	
	local boxAdornment = Instance.new("BoxHandleAdornment", workspace)
	boxAdornment.Adornee = workspace.Terrain
	boxAdornment.Size = regionSize
	boxAdornment.CFrame = CFrame.new(chosenPosition)
	boxAdornment.Transparency = 0.5
	boxAdornment.Color3 = Color3.fromRGB(255, 0, 0)
end

local function checkForDirt(chosenPosition)

	local searchRadius = (placingDirt.Size.X / 2) + 0.25 -- if your dirt isn't a square, change it to a number
	local searchVector = Vector3.new(searchRadius, searchRadius, searchRadius)

	local searchRegion = Region3.new(chosenPosition - searchVector, chosenPosition + searchVector)
	local dirtParts = workspace:FindPartsInRegion3(searchRegion, nil, math.huge)
	
	for _, part in ipairs(dirtParts) do
		if part.Name == placingDirt.Name then
			print("Dirt found within " .. searchRadius ..  " studs.")
			return true
		end
	end
	
	
	if not showRegions then
		return
	end
	
	placeRegion(searchRegion, chosenPosition)
	
	return false
end


local function plant(player, character)

	local clonedDirt = placingDirt:Clone()

	local humRootPart = character:FindFirstChild("HumanoidRootPart")
	local humanoid = character:FindFirstChild("Humanoid")

	if humanoid.FloorMaterial ~= Enum.Material.Grass then
		print(player.Name .. " wasn't on grass.")
		return
	end

	local raycastParameters = RaycastParams.new()
	raycastParameters.FilterDescendantsInstances = {tool.Parent}

	local raycastResult = workspace:Raycast(humRootPart.Position, Vector3.new(0, -6, 0), raycastParameters)
	local chosenPosition = raycastResult.Position + Vector3.new(0, clonedDirt.Size.Y / 2, 0)

	if raycastResult then
		if not checkForDirt(chosenPosition) then
			clonedDirt.Position = chosenPosition
			clonedDirt.Orientation = defaultDirtRotation
			clonedDirt.Parent = dirtFolder
			
			print(player.Name .. " farmed dirt.")
		end
	end
end


tool.Activated:Connect(function()

	local character = tool.Parent
	local player = game.Players:GetPlayerFromCharacter(character)
	
	if placingOnCooldown == true then
		return
	end
	
	placingOnCooldown = true
	plant(player, character)
	wait(1)
	placingOnCooldown = false
end)

@NateDV10

1 Like

This works but its so complicated… Anyways the final thing I need to get working is a zone that follows the player whenever they equip the hoe (its just like a building overlay). This would show the player where the dirt is getting placed. I already have the model but I don’t know if highlights work on mesh parts, and I cant get the part to stop falling into the void (because its not anchored and non collidable). Sorry if I’m asking for a lot :sick:

Maybe a different way of going about it …
LocalScript in StarterCharacterScripts

task.wait(5) -- a stall to mimic the tool being used

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")

local clonedObject = game.Workspace:WaitForChild("ClonedObject"):Clone()

local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Include
raycastParams.FilterDescendantsInstances = {character}

local raycastResult = game.Workspace:Raycast(humanoidRootPart.Position, Vector3.new(0, -100, 0), raycastParams)

if raycastResult then
	clonedObject.Parent = game.Workspace
	clonedObject.CFrame = CFrame.new(raycastResult.Position + Vector3.new(0, clonedObject.Size.Y / 2, 0))
else
	warn("Could not find ground beneath the player.")
end

This is working if set up right. But it is just a test shot and will need some love.

Just weld a massless uncollidable visible part to the handle (if you have a handle, if not, make a invisible handle)

Could you add me to a Team Create session?

I could help you a lot more (even with other things) and I have a lot of free time for the next few weeks.

1 Like

Would welding it to the character work?

I don’t need that much help on this lol, I’ve almost finished the system thanks to you and @phenix_rider1.

welding it to the character would make it visible even without holding the hoe no?

unless you add a script