totallynotcopied

Untitled

May 10th, 2020
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1. --[[
  2. Delete With Undo v1 by angeld23
  3.  
  4. Default keybinds:
  5. [Right Click + Left Ctrl] - Deletes part that your mouse is pointing at.
  6. [Right Click + X] - Undo last deletion. Can be repeated until all parts are returned.
  7. [Right Click + C] - Undo all deletions. This will return every part at once.
  8.  
  9. (You cannot hold the key and then right click, you must hold right click first. If anyone can fix that, it would be highly appreciated!)
  10.  
  11. Set custom keybinds in the settings below.
  12.  
  13. Report any bugs to angeld23 on v3rm (or Synapse Forums).
  14.  
  15. My Discord: angeld23#5601
  16. --]]
  17.  
  18.  
  19.  
  20. --Settings
  21. deleteKey = Enum.KeyCode.LeftControl --Key to delete the part you are looking at.
  22. undoKey = Enum.KeyCode.X --Key to undo last deletion.
  23. undoAllKey = Enum.KeyCode.C --Key to undo all deletions.
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44. --Variables
  45. plr = game.Players.LocalPlayer
  46. mouse = plr:GetMouse()
  47. input = game:GetService("UserInputService")
  48. storage = game:GetService("ReplicatedStorage")
  49. undoTable = {}
  50.  
  51. --Folder to hold deleted parts
  52. if not storage:FindFirstChild("DeleteWithUndo") then
  53. folder = Instance.new("Folder", storage)
  54. folder.Name = "DeleteWithUndo"
  55. end
  56. --Click detection
  57. clicking = false
  58. mouse.Button2Down:connect(function()
  59. clicking = true
  60. end)
  61. mouse.Button2Up:connect(function()
  62. clicking = false
  63. end)
  64.  
  65. --Input detection
  66. input.InputBegan:connect(function(key)
  67. if key.KeyCode == deleteKey and clicking then
  68. local targetPart = mouse.Target
  69. print("Deleted "..targetPart.Name)
  70. if not targetPart or not targetPart:IsA("BasePart")then return end
  71. local clone = targetPart:Clone()
  72. clone.Parent = folder
  73. local savedParent = Instance.new("ObjectValue", clone)
  74. savedParent.Name = "S_P"
  75. savedParent.Value = targetPart.Parent
  76. targetPart:Destroy()
  77. table.insert(undoTable, #undoTable + 1, clone)
  78. end
  79. if key.KeyCode == undoKey and #undoTable > 0 and clicking then
  80. local targetPart = undoTable[#undoTable]
  81. if not targetPart.S_P.Value then print("This part's parent was deleted! Setting parent to game.Workspace.") targetPart.Parent = workspace targetPart.S_P:Destroy() table.remove(undoTable, #undoTable) else
  82. print("Undone deletion of "..targetPart.Name)
  83. targetPart.Parent = targetPart.S_P.Value
  84. targetPart.S_P:Destroy()
  85. table.remove(undoTable, #undoTable)
  86. end
  87. end
  88. if key.KeyCode == undoAllKey and clicking then
  89. for i = 1, #undoTable do
  90. local targetPart = undoTable[#undoTable]
  91. print(targetPart.Name)
  92. if not targetPart.S_P.Value then print("This part's parent was deleted! Setting parent to game.Workspace.") targetPart.Parent = workspace targetPart.S_P:Destroy() table.remove(undoTable, #undoTable) else
  93. targetPart.Parent = targetPart.S_P.Value
  94. targetPart.S_P:Destroy()
  95. table.remove(undoTable, #undoTable)
  96. end
  97. end
  98. print("Undone deletion of all parts.")
  99. end
  100. end)
  101.  
  102. warn("Delete With Undo v1 by angeld23 loaded!")
  103. warn("Report bugs to:")
  104. warn("angeld23 on v3rm")
  105. warn("angeld23 on Synapse Forums")
  106. warn("angeld23#5601 on discord")
Add Comment
Please, Sign In to add comment