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)