Auto pickup keycard/m9 open SRC
Key Required

Auto pickup keycard/m9 open SRC

Prison Lifedai1228dai1228 1.1K views 38 executesUpdated Dec 27, 2025
5.0/ 5(1 votes)
10100% Positive
Lua Script•88 lines (2564 chars)
local tick, pairs, pcall = tick, pairs, pcall

local player = game:GetService("Players").LocalPlayer
local remote = game:GetService("ReplicatedStorage"):WaitForChild("Remotes"):WaitForChild("GiverPressed")
local run = game:GetService("RunService")

local grab_dist = 12 -- max grab distance (12 studs max)
local grab_delay = 1 -- seconds to wait after detecting before grabbing

local grab_dist_sq = grab_dist * grab_dist
local grabbables = {}
local first_seen = {}

local function is_grabbable(obj)
    if not obj:IsA("Model") then return false end
    local n = obj.Name:lower()
    return n:find("keycard") or n == "m9"
end

local function is_owned(obj)
    local ancestor = obj.Parent
    while ancestor and ancestor ~= workspace do
        if ancestor:FindFirstChild("Humanoid") then return true end
        if ancestor.Name == "Backpack" then return true end
        ancestor = ancestor.Parent
    end
    return false
end

local function get_part(model)
    return model.PrimaryPart or model:FindFirstChildWhichIsA("BasePart", true)
end

local function dist_sq(a, b)
    local d = a - b
    return d.X * d.X + d.Y * d.Y + d.Z * d.Z
end

for _, obj in pairs(workspace:GetDescendants()) do
    if is_grabbable(obj) then grabbables[obj] = true end
end

workspace.DescendantAdded:Connect(function(obj)
    if is_grabbable(obj) then grabbables[obj] = true end
end)

workspace.DescendantRemoving:Connect(function(obj)
    grabbables[obj] = nil
    first_seen[obj] = nil
end)

local last_grab = 0

run.Heartbeat:Connect(function()
    local now = tick()
    if now - last_grab < 0.05 then return end

    local char = player.Character
    if not char then return end

    local root = char:FindFirstChild("HumanoidRootPart")
    if not root then return end

    local my_pos = root.Position

    for item in pairs(grabbables) do
        if not item.Parent then
            grabbables[item] = nil
            first_seen[item] = nil
        elseif is_owned(item) then
            first_seen[item] = nil
        else
            local part = get_part(item)
            if part and dist_sq(my_pos, part.Position) <= grab_dist_sq then
                if not first_seen[item] then
                    first_seen[item] = now
                elseif now - first_seen[item] >= grab_delay then
                    last_grab = now
                    first_seen[item] = nil
                    pcall(remote.FireServer, remote, item)
                    return
                end
            else
                first_seen[item] = nil
            end
        end
    end
end)

Features & Information

not much to say its just a super basic auto pickup keycard/m9 script and also optimized so it doesnt lag (made by claude opus 4.5 (and me kinda) >~<)

Community Comments (1)

dai1228dai1228Dec 27, 2025

top 5 most basic and easy scripts to make :sob:

More Scripts for Prison Life