now make it so it only floats zand stays if its touching another object liek its…
- User
now make it so it only floats zand stays if its touching another object liek its clipping with anohter object it will be weleded tyo that obnject but if its just touching air it will fall to the ground
Assistant
Here's the updated script that will weld parts when they're clipping/intersecting with other objects, but let them fall when they're just in air:
-- Building System Script -- Place this LocalScript in StarterGui or StarterPlayerScripts local Players = game:GetService("Players") local UserInputService = game:GetService("UserInputService") local RunService = game:GetService("RunService") local Camera = workspace.CurrentCamera local player = Players.LocalPlayer local mouse = player:GetMouse() -- Define the folder name local DRAGABLE_FOLDER_NAME = "Dragable" -- Find the Dragable folder in the workspace local dragableFolder = workspace:FindFirstChild(DRAGABLE_FOLDER_NAME) -- Variables local heldPart = nil local holding = false local connection = nil local originalCFrame = nil local rotationX, rotationY, rotationZ = 0, 0, 0 -- Settings local PICKUP_DISTANCE = 50 -- Maximum distance to pick up parts local ROTATION_INCREMENT = 15 -- Degrees to rotate per key press local INTERSECTION_THRESHOLD = 0.1 -- Minimum overlap to consider as intersection -- Check if the Dragable folder exists if not dragableFolder or not dragableFolder:IsA("Folder") then warn("Building System: Could not find a Folder named '" .. DRAGABLE_FOLDER_NAME .. "' in Workspace. Pickup will not work.") script.Enabled = false return end -- Function to check if a part can be picked up local function canPickUp(part) if not part:IsA("BasePart") then return false end if part.Parent ~= dragableFolder then return false end return true end -- Function to get the bounding box of a part local function getPartBounds(part) local cf, size = part:GetBoundingBox() return cf, size end -- Function to check if two bounding boxes intersect significantly local function doBoxesIntersect(cf1, size1, cf2, size2) -- Convert to world space positions local pos1 = cf1.Position local pos2 = cf2.Position -- Calculate half sizes local half1 = size1 / 2 local half2 = size2 / 2 -- Check for intersection on each axis local xOverlap = math.abs(pos1.X - pos2.X) < (half1.X + half2.X - INTERSECTION_THRESHOLD) local yOverlap = math.abs(pos1.Y - pos2.Y) < (half1.Y + half2.Y - INTERSECTION_THRESHOLD) local zOverlap = math.abs(pos1.Z - pos2.Z) < (half1.Z + half2.Z - INTERSECTION_THRESHOLD) return xOverlap and yOverlap and zOverlap end -- Function to find intersecting parts local function findIntersectingPart(part) local partCF, partSize = getPartBounds(part) local touchingParts = part:GetTouchingParts() for _, touchingPart in ipairs(touchingParts) do -- Ignore parts in the dragable folder, player character, and the part itself if touchingPart ~= part and touchingPart.Parent ~= dragableFolder and not touchingPart:IsDescendantOf(player.Character or workspace) then local touchingCF, touchingSize = getPartBounds(touchingPart) -- Check if they're actually intersecting (not just touching) if doBoxesIntersect(partCF, partSize, touchingCF, touchingSize) then return touchingPart end end end return nil end -- Function to weld two parts together local function weldParts(part1, part2) -- Remove any existing welds on part1 for _, child in ipairs(part1:GetChildren()) do if child:IsA("WeldConstraint") and child.Name == "BuildingWeld" then child:Destroy() end end -- Create new weld local weld = Instance.new("WeldConstraint") weld.Name = "BuildingWeld" weld.Part0 = part1 weld.Part1 = part2 weld.Parent = part1 -- Make sure the part is anchored part1.Anchored = true return weld end -- Function to remove all building welds from a part local function removeWelds(part) for _, child in ipairs(part:GetChildren()) do if child:IsA("WeldConstraint") and child.Name == "BuildingWeld" then child:Destroy() end end end -- Function to pick up a part local function pickUpPart(part) if not canPickUp(part) then return end -- Remove any existing welds before picking up removeWelds(part) heldPart = part holding = true originalCFrame = part.CFrame rotationX, rotationY, rotationZ = 0, 0, 0 -- Make part non-collidable and anchored while holding part.CanCollide = false part.Anchored = true -- Start the hold loop connection = RunService.Heartbeat:Connect(function() if heldPart and holding then updateHeldPart() end end) end -- Function to update held part position function updateHeldPart() if not heldPart then return end local camera = workspace.CurrentCamera local unitRay = camera:ScreenPointToRay(mouse.X, mouse.Y) local distance = 10 local targetPosition = unitRay.Origin + unitRay.Direction * distance local rotation = CFrame.Angles( math.rad(rotationX), math.rad(rotationY), math.rad(rotationZ) ) heldPart.CFrame = CFrame.new(targetPosition) * rotation end -- Function to place the part local function placePart() if not heldPart or not holding then return end holding = false -- Restore collision detection heldPart.CanCollide = true -- Wait a couple frames for physics to update wait(0.1) -- Check if the part is intersecting with another object local intersectingPart = findIntersectingPart(heldPart) if intersectingPart then -- Part is intersecting with another object - weld it weldParts(heldPart, intersectingPart) print("Part welded to: " .. intersectingPart.Name) else -- Part is in open air - let it fall heldPart.Anchored = false print("Part released to fall") end -- Clean up if connection then connection:Disconnect() connection = nil end heldPart = nil rotationX, rotationY, rotationZ = 0, 0, 0 end -- Mouse click to pick up parts mouse.Button1Down:Connect(function() if holding then placePart() else local target = mouse.Target if target and target.Parent then local distance = (target.Position - Camera.CFrame.Position).Magnitude if distance <= PICKUP_DISTANCE then if canPickUp(target) then pickUpPart(target) end end end end end) -- Keyboard input for rotation and cancel UserInputService.InputBegan:Connect(function(input, gameProcessed) if gameProcessed or not holding or not heldPart then return end if input.KeyCode == Enum.KeyCode.R then rotationX = rotationX + ROTATION_INCREMENT elseif input.KeyCode == Enum.KeyCode.T then rotationY = rotationY + ROTATION_INCREMENT elseif input.KeyCode == Enum.KeyCode.Y then rotationZ = rotationZ + ROTATION_INCREMENT elseif input.KeyCode == Enum.KeyCode.Escape then -- Cancel pickup if heldPart then heldPart.CFrame = originalCFrame heldPart.CanCollide = true heldPart.Anchored = false end holding = false if connection then connection:Disconnect() connection = nil end heldPart = nil rotationX, rotationY, rotationZ = 0, 0, 0 end end) -- Handle player leaving (cleanup) Players.PlayerRemoving:Connect(function(leavingPlayer) if leavingPlayer == player and holding then placePart() end end) print("Building system loaded! Parts will weld when intersecting with objects, fall when in open air.")Key Changes:
-
Improved Intersection Detection:
getPartBounds(): Gets the bounding box of a partdoBoxesIntersect(): Checks if two bounding boxes actually overlap significantly (not just touching)findIntersectingPart(): Finds the first part that the held part is actually intersecting with
-
Welding System:
weldParts(): Creates a WeldConstraint between two partsremoveWelds(): Removes existing building welds when picking up a part- Parts that intersect get welded and stay anchored
-
Smart Placement Logic:
- If intersecting with another object → Weld and stay floating
- If in open air → Unanchor and let fall
- Uses
INTERSECTION_THRESHOLDto determine significant overlap vs just touching
-
Better Physics Handling:
- Added a small wait after enabling collision to let physics update
- Removes old welds when picking up previously welded parts
How it works:
- Intersecting/Clipping: When you place a part and it's overlapping with another object by more than the threshold, it gets welded to that object and stays floating
- Open Air: When you place a part in empty space, it becomes unanchored and falls due to gravity
- Visual Feedback: Console messages tell you whether a part was welded or released to fall
The
INTERSECTION_THRESHOLDvariable controls how much overlap is needed to consider it an intersection rather than just touching. You can adjust this value to make the system more or less sensitive.-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.