Advertisement
sriyanto

KeyModule (Piggy Game)

Apr 6th, 2024 (edited)
691
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.67 KB | None | 0 0
  1. local module = {}
  2. function module.DropTools(plr,map,position)
  3.     -- Look for any tools that are in your Backpack
  4.     for i, tool in pairs(plr.Backpack:GetChildren()) do
  5.         if tool:IsA("Tool") and game.ServerStorage.KeyHandles:FindFirstChild(tool.Name) then
  6.             local clone = game.ServerStorage.KeyHandles:FindFirstChild(tool.Name):Clone()      
  7.             if clone:IsA("Model") then
  8.                 clone:SetPrimaryPartCFrame(CFrame.new(position))
  9.             else
  10.                 clone.Position = position
  11.             end    
  12.             clone.Parent = map.Items       
  13.             tool:Destroy()     
  14.         end
  15.     end
  16.     -- Look for any tools that are in your Character
  17.     for i, tool in pairs(plr.Character:GetChildren()) do
  18.         if tool:IsA("Tool") and game.ServerStorage.KeyHandles:FindFirstChild(tool.Name) then   
  19.             local clone = game.ServerStorage.KeyHandles:FindFirstChild(tool.Name):Clone()  
  20.             if clone:IsA("Model") then
  21.                 clone:SetPrimaryPartCFrame(CFrame.new(position))
  22.             else
  23.                 clone.Position = position
  24.             end    
  25.             clone.Parent = map.Items       
  26.             tool:Destroy()     
  27.         end
  28.     end
  29. end
  30. function module.Clicked(plr,item)
  31.     if plr then
  32.         if plr.Character and not plr:FindFirstChild("Piggy") then      
  33.             local position     
  34.             if item:IsA("Model") then
  35.                 position = item.PrimaryPart.Position
  36.             else
  37.                 position = item.Position
  38.             end        
  39.             module.DropTools(plr,game.Workspace.Map,position)
  40.             print("Dropped Keyhandles")        
  41.             if game.ServerStorage.Tools:FindFirstChild(item.Name) then             
  42.                 local clonedTool = game.ServerStorage.Tools[item.Name]:Clone()
  43.                 clonedTool.Parent = plr.Backpack           
  44.                 plr.Character.Humanoid:EquipTool(clonedTool)           
  45.                 item:Destroy()             
  46.                 print("Equipped the tool object")          
  47.             end        
  48.         end
  49.     end
  50. end
  51. return module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement