How would I make a system like this

So, there is a game called cook burgers, and I would love to recreate the grabbing system.

The system that allows you to pick up objects, and keeps the objects in a certain range of you, only problem is I have no idea how, so does anybody know?

one way of doing is adding a click detect and a script inside
and detect clicks,
once you do that you weld the item to the humanoidrootpart’s lookvector with an offset.x of how long in studs you want
and you can detect if the item is held and when it is clicked again u can destroy the weld

local blockPart = script.Parent
local function handleDrag(player, mouse)
    local character = player.Character
    local humanoid = character:WaitForChild("Humanoid")

    local startPos = blockPart.Position
    local offset = blockPart.Position - mouse.Hit.p
    local canMove = true

    -- Listen for mouse events
    mouse.Button1Down:Connect(function()
        if humanoid and humanoid.Health > 0 then
            canMove = true
        end
    end)

    mouse.Button1Up:Connect(function()
        canMove = false
    end)

    mouse.Move:Connect(function()
        if canMove then
            local newPosition = mouse.Hit.p + offset
            blockPart.Position = newPosition
        end
    end)
end

game.Players.PlayerAdded:Connect(function(player)
    -- Create a new mouse object for the player
    local mouse = player:GetMouse()

    -- Call the handleDrag function when the player clicks and drags
    mouse.Button1Down:Connect(function()
        handleDrag(player, mouse)
    end)
end)
1 Like