Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I make a undeletable brick?

I'm not trying to make a virus here. I'm just working on an anti exploit system just for my game. I want to figure out how to make a brick respawn in game at it's same exact size and position.

2 answers

✓ Accepted answer

Destroying an object is just a matter of setting it's parent to nil. There is a difference, of course, between obj.Parent = nil and obj:Destroy(), but they are both setting the parent to nil. You cannot stop someone from destroying an object in your game unless you create some sandbox or wrapper in which you control how the functions behave.

However, there's the common pseudo-solution of "locking" the object's parent by waiting until it's destroyed, then cloning it back to it's original parent. Example:

local lockedPart = workspace:WaitForChild("LockedPart")

workspace.ChildRemoved:Connect(function(object)
	if object == lockedPart then
		local newLockedPart = lockedPart:Clone()
		newLockedPart.Parent = workspace
		lockedPart = newLockedPart -- update memory with new part
	end
end)

There are of course variations to this, such as using DescendantRemoving if the object is within some deeper hierarchy.

It's also worth noting that if the script is removed, modified, or disabled, the object will of course be destroy-able again. Thus why this is not really a good solution for preventing an exploit where you expect someone to be destroying objects on the server. Just keep filtering enabled on, and design your game such that clients don't have permission to execute high-level commands on the server.

2 comments

0

great answer, but Destroy() and setting parent to nil are different; when you call Destroy() the destructor of the object is called, therefore removing it from memory, but setting to nil just changes the Parent field of the object

0

Yeah, I mentioned that they're different. However, Destroy does still set the parent to nil. It's a "all squares are rectangles but not all rectangles are squares" sort of thing. A does B but B doesn't necessarily do A. I guess I could have been clearer about that.

You can do an undeletable brick by doing this by parenting this script to your brick that you want to make it undeletable.

local part = script.Parent

--= Brick Properties =--
local function respawnBrick()
	local debounce = false
	debounce = true -- this debounce prevents part to clone another time 
	local brickclone = Instance.new("Part")
	brickclone.BrickColor = Color3.fromRGB.new(0,0,0) -- your part's RGB value
	brickclone.Position = Vector3.new(0,0,0) -- the part's Position
	brickclone.Size = Vector3.new(0,0,0) -- the part's size
	brickclone.Anchor = true
	brickclone.CanCollide = true
	debounce = false
end)
--= Brick Properties =--

while wait(1) do -- update the script every 1 second
	if part then -- if there still have the part
		print("The brick is there")
		else
		print("The brick have been deleted")
		respawnBrick()
	end
end

Here you go! If you have more questions or confusing what I've said, comment below, and I'll be glad to help. Bye!

####Edits: Scripts problems, grammars problems, confusing sentences

This discussion is preserved as it was. New answers, comments, and votes are closed.