Skip to content
TheChatArchiveThe Chat Archive
Metallama-4-maverick-03-26-experimental· MetaHugging Face LMArena Human Preference 140K

now make it so it only floats zand stays if its touching another object liek its…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Claudeclaude-sonnet-4-20250514-thinking-32k’s answer.
  1. 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

  2. Meta Assistant

    Let's modify the script to implement the following behavior:

    1. Float-and-Stick Logic:
      • When placing a part, it will temporarily float just above the point where you released the mouse.
      • The part will check for collisions (touching other parts).
      • If it's touching another solid object (not just air), it will weld itself to that object (or at least anchor itself in place).
      • If it's not touching anything solid (just floating in air), it will start falling due to gravity until it hits the ground or another object.

    Here's the updated LocalScript:

    -- 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 PhysicsService = game:GetService("PhysicsService")
    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 FLOAT_CHECK_DELAY = 0.2 -- Seconds to wait before checking if part should fall or stick
    
    -- 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 check if part is touching solid objects (not just air)
    local function isPartTouchingSolid(part)
        -- Get all parts touching this part
        local touchingParts = part:GetTouchingParts()
        
        -- Filter out parts that are:
        -- 1. The part itself
        -- 2. Inside the Dragable folder (we don't want self-collisions or sibling collisions to count)
        -- 3. Non-solid (e.g., transparent or CanCollide=false parts)
        for _, touchingPart in ipairs(touchingParts) do
            if touchingPart ~= part 
            and touchingPart.Parent ~= dragableFolder 
            and touchingPart.CanCollide 
            and (not PhysicsService:IsPartCollisionGroupEnabled("NoBuildCollision") or not PhysicsService:IsPartInCollisionGroup(touchingPart, "NoBuildCollision")) then
                return true -- Found a solid touch
            end
        end
        
        return false -- Only touching air or irrelevant parts
    end
    
    -- Function to pick up a part
    local function pickUpPart(part)
        if not canPickUp(part) then return end
    
        heldPart = part
        holding = true
        originalCFrame = part.CFrame
        rotationX, rotationY, rotationZ = 0, 0, 0
    
        part.CanCollide = false
        part.Anchored = true
    
        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 + Vector3.new(0, 0.5, 0)
    
        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 (new float-and-stick logic)
    local function placePart()
        if not heldPart or not holding then return end
    
        holding = false
    
        -- Step 1: Release the part at the current position (but keep it non-colliding for now)
        heldPart.CanCollide = false
        heldPart.Anchored = true -- Keep it suspended
    
        -- Step 2: Wait a short duration (FLOAT_CHECK_DELAY) to let physics settle
        wait(FLOAT_CHECK_DELAY)
    
        -- Step 3: Re-enable collision *just* for the touch check
        heldPart.CanCollide = true
    
        -- Step 4: Check if it's touching anything solid
        if isPartTouchingSolid(heldPart) then
            -- It's clipping or resting on something solid. WELD IT.
            heldPart.Anchored = true -- Keep it locked in place
            -- Optional: Create a weld or constraint for stronger attachment
            -- We'll use a simple WeldConstraint for demonstration
            local weld = Instance.new("WeldConstraint")
            weld.Parent = heldPart
            local touchingParts = heldPart:GetTouchingParts()
            for _, otherPart in ipairs(touchingParts) do
                if otherPart ~= heldPart and otherPart.CanCollide and otherPart.Parent ~= dragableFolder then
                    weld.Part0 = heldPart
                    weld.Part1 = otherPart
                    break -- Weld to the first valid solid part
                end
            end
        else
            -- It's floating in air. LET IT FALL.
            heldPart.Anchored = false -- Gravity will take over
        end
    
        -- Cleanup
        if connection then
            connection:Disconnect()
            connection = nil
        end
    
        heldPart = nil
        rotationX, rotationY, rotationZ = 0, 0, 0
    end
    
    -- Mouse click to pick up/place 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 and canPickUp(target) then
                    pickUpPart(target)
                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
            if heldPart then
                heldPart.CFrame = originalCFrame
                heldPart.CanCollide = true
                heldPart.Anchored = false
            end
            heldPart = nil
            holding = false
            rotationX, rotationY, rotationZ = 0, 0, 0
            if connection then
                connection:Disconnect()
                connection = nil
            end
        end
    end)
    
    -- Handle player leaving (cleanup)
    Players.PlayerRemoving:Connect(function(leavingPlayer)
        if leavingPlayer == player and holding then
            placePart()
        end
    end)
    
    print("Building system loaded! Dragable parts float then stick if touching solids, otherwise fall.")
    

    Key Changes:

    1. placePart() Logic Overhaul:
      • After releasing the mouse, the part is kept anchored and non-colliding for a brief moment (FLOAT_CHECK_DELAY, 0.2 seconds).
      • Then, collision is re-enabled (CanCollide = true) just for the physics engine to register any touching parts.
      • isPartTouchingSolid(heldPart) checks if the part is touching any solid, collidable object outside the Dragable folder.
      • If touching solid: The part stays anchored (Anchored = true). Optionally, a WeldConstraint is created between the held part and the first solid part it touches. This "welds" them together.
      • If not touching solid (floating): The part becomes unanchored (Anchored = false), and gravity takes over. It will fall until it hits something.
    2. isPartTouchingSolid(part) Function:
      • Uses part:GetTouchingParts() to get all parts in contact.
      • Filters the list:
        • Ignores the part itself.
        • Ignores parts inside the Dragable folder (siblings or self).
        • Only counts parts where CanCollide == true (solid objects).
      • Returns true if any valid solid touch is found; otherwise, false (it's in mid-air).
    3. Welding (Optional but Recommended):
      • If you want parts to truly "stick" together, a WeldConstraint is created between the placed part and the first valid solid part it touches.
      • This prevents them from sliding apart later.

    Behavior Summary:

    • Pick up a part from the Dragable folder by clicking on it.
    • Move it around with the camera.
    • Rotate using R (X-axis), T (Y-axis), Y (Z-axis).
    • Place by clicking again.
    • Immediately after placement:
      • If the part is overlapping or resting on another solid object, it will anchor itself (and optionally weld).
      • If the part is floating in air, it will start falling due to gravity.
    • Press ESC to cancel placement and return the part to its original spot.

    Notes:

    • Make sure other objects in the workspace (e.g., terrain, buildings) have CanCollide = true for the touch detection to work.
    • If you want even stronger attachment, explore using Motor6D or other constraints instead of WeldConstraint.
    • Adjust FLOAT_CHECK_DELAY if parts aren't sticking as expected (increase if physics is slow, decrease if you want snappier placement).

    Now, your building system has a more realistic "float then stick" behavior!

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.