Gravity to build system

Btw guys. Why using Raycasting when you can get all welded parts using BasePart:GetConnectedParts()

Edit: you can also do: BasePart:GetJoints()

Do you have a script that would use this please?

You can also do BasePart:GetRootPart() which will get the most important part in which case if assembly has anchored part, the it will always return the anchored part. So you can easily check if parts are floating.

Nope im at school. I ain’t writing whold code on a screen keyboard but it shouldn’t be hard to make. If you read the documentation you should be able to do it yourself.

I’ll try to update the code sometime later today, but for now I’m taking a break from coding. And what you requested should be rather simple to implement.

So i tried to make my own weld script but it only welds the parts that are placed 2 blocks high and is placed on the side how do i fix it?

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local BlocksPlace = game.Workspace:WaitForChild("Blocks")

local function createWeld(part1, part2)
	local weld = Instance.new("WeldConstraint")
	weld.Part0 = part1
	weld.Part1 = part2
	weld.Parent = part1
end

local function isTouchingGround(part)
	local touchingParts = part:GetTouchingParts()
	for _, touchingPart in pairs(touchingParts) do
		if touchingPart.Name == "Baseplate" then
			return true
		end
	end
	return false
end

local function unanchorConnectedParts(part)
	local connectedParts = part:GetConnectedParts()
	for _, connectedPart in ipairs(connectedParts) do
		if connectedPart.Anchored then
			connectedPart.Anchored = false
		end
		-- unanchor connected parts
		unanchorConnectedParts(connectedPart)
	end
end

ReplicatedStorage.place.OnServerEvent:Connect(function(player, Positiona, Matpicked)
	if not ReplicatedStorage.Blocks:FindFirstChild(Matpicked) then
		warn("Material not found: " .. Matpicked)
		return
	end

	local shape = ReplicatedStorage.Blocks[Matpicked]:Clone()
	local tag = Instance.new("StringValue")
	tag.Name = "blockowner"
	tag.Value = player.Name
	tag.Parent = shape

	shape.Size = Vector3.new(3, 3, 3)
	shape.CFrame = Positiona
	shape.Parent = BlocksPlace

	if isTouchingGround(shape) then
		shape.Anchored = true
	else
		shape.Anchored = false
		local partsTouching = shape:GetTouchingParts()
		for _, part in ipairs(partsTouching) do
			if part:IsDescendantOf(BlocksPlace) then
				createWeld(part, shape)
			end
		end
	end
end)

ReplicatedStorage.del.OnServerEvent:Connect(function(player, target)
	if target and target:IsA("BasePart") then
		-- Destroy the target part
		target:Destroy()

		-- Get the root part of the assembly (the part that is anchored)
		local rootPart = target:GetRootPart()

		-- Unanchor all parts connected to the root part
		if rootPart then
			unanchorConnectedParts(rootPart)
		end
	else
		warn("Invalid target for deletion")
	end
end)
1 Like

This could be wrong but in the place where you call createWeld(part, shape) there might be a chance that the placed block is 0.001 studs off so its technically not touching the other blocks

1 Like

So how would i fix it?

sdjfSDJfdjashe