Advertisement
HowToRoblox

ToolPickupHandler

Dec 29th, 2020
7,312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.95 KB | None | 0 0
  1. local pps = game:GetService("ProximityPromptService")
  2.  
  3.  
  4. local distance = 10
  5. local timeToHold = 0.5
  6.  
  7.  
  8. pps.PromptTriggered:Connect(function(pp, plr)
  9.    
  10.     local tool = pp.Parent.Parent
  11.     if tool:IsA("Tool") then
  12.        
  13.         tool.Parent = plr.Backpack
  14.        
  15.         pp:Destroy()
  16.     end
  17. end)
  18.  
  19.  
  20. while wait() do
  21.    
  22.    
  23.     for i, descendant in pairs(workspace:GetDescendants()) do
  24.        
  25.         if descendant:IsA("Tool") and descendant:FindFirstChild("Handle") and not game.Players:GetPlayerFromCharacter(descendant.Parent) then
  26.            
  27.            
  28.             if descendant.Handle:FindFirstChild("TouchInterest") then descendant.Handle.TouchInterest:Destroy() end
  29.            
  30.            
  31.             local pp = descendant.Handle:FindFirstChild("ProximityPrompt")
  32.            
  33.             if not pp then
  34.                
  35.                 pp = Instance.new("ProximityPrompt")
  36.                 pp.MaxActivationDistance = distance
  37.                 pp.HoldDuration = timeToHold
  38.                 pp.ObjectText = "Tool"
  39.                 pp.ActionText = "Pick Up"
  40.                
  41.                 pp.Parent = descendant.Handle
  42.             end
  43.         end
  44.     end
  45. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement