Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- f1 - remove
- -- f2 - undo
- -- f4 - undo all
- -- LocalScript in StarterPlayerScripts
- local UserInputService = game:GetService("UserInputService")
- local Players = game:GetService("Players")
- local player = Players.LocalPlayer
- local mouse = player:GetMouse()
- -- table of removed objects
- local removedStack = {}
- -- check: is the object part of a character (does the model have a Humanoid)?
- local function isCharacterPart(part)
- if part and part.Parent then
- if part.Parent:FindFirstChildOfClass("Humanoid") then
- return true
- end
- end
- return false
- end
- -- delete the object under the cursor
- local function deletePartUnderCursor()
- local target = mouse.Target
- if target and (target:IsA("Part") or target:IsA("MeshPart") or target:IsA("UnionOperation")) then
- if isCharacterPart(target) then
- warn("You cannot delete character parts!")
- return
- end
- -- save the object and its parent in the stack
- table.insert(removedStack, {
- object = target,
- parent = target.Parent
- })
- target.Parent = nil -- hide the object
- print("Deleted object:", target.Name, "(in stack:", #removedStack .. ")")
- else
- print("No suitable object under the cursor")
- end
- end
- -- restore the last removed object
- local function restoreLastPart()
- if #removedStack > 0 then
- local data = table.remove(removedStack) -- get the last one
- if data.object and data.parent then
- data.object.Parent = data.parent
- print("Restored object:", data.object.Name, "(remaining in stack:", #removedStack .. ")")
- end
- else
- warn("No removed objects to restore")
- end
- end
- -- restore all removed objects
- local function restoreAllParts()
- if #removedStack > 0 then
- for i = #removedStack, 1, -1 do
- local data = removedStack[i]
- if data.object and data.parent then
- data.object.Parent = data.parent
- end
- table.remove(removedStack, i)
- end
- print("All objects restored")
- else
- warn("No removed objects to restore")
- end
- end
- -- key input handling
- UserInputService.InputBegan:Connect(function(input, gameProcessed)
- if not gameProcessed then
- if input.KeyCode == Enum.KeyCode.F1 then
- deletePartUnderCursor()
- elseif input.KeyCode == Enum.KeyCode.F2 then
- restoreLastPart()
- elseif input.KeyCode == Enum.KeyCode.F4 then
- restoreAllParts()
- end
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment