How To Check If An Object Was Inserted

I’m currently taking on a task to prevent exploiters but I’ve ran into a problem. What I want to do is check if part is inserted but unfortunately I don’t know how to do that. I also feel like this is impossible but let’s see.
Here’s my script I tried:

  game.Players.PlayerAdded:Connect(function()
 local insertedscript = Instance.new("Script")
         if insertedscript then
   insertedscript:Destroy()
  end
       end)

I hope this is possible though so I can achieve this.

Instance.new() inserts something. It does not detect if something is added.

To check if something is added though you can use this:

game.Workspace(or whatever the parent is).ChildAdded:Connect(function()
If you would like you can put in the parentheses after function a value to use as the thing added.

To check if an Instance is added to something, you can use Child Added.

However, you can’t detect when exploiters use a script as it doesn’t have to be an Instance and it really never is. Even if you use ChildAdded on the client to detect a specific exploit, for example, you would still have to compare it to the server and make sure it was on the client only. Anything you do to prevent exploiting on the client can be bypassed.

I tried something like this, obviously didn’t work though:

game.Players.PlayerAdded:Connect(function()
	workspace.ChildAdded:Connect(function(child)
		if child:IsA("Script") then
			child:Destroy()
		end
	end)
end)

It is basically impossible to script something that detects when something is added that is not you and have it find the person and kick/ban them.

You can’t really use this to prevent exploits, you’d need to just make your script’s secure and make sure you don’t have any backdoors which can give player’s access to the server.

And I don’t think exploits do insert script’s.

But you can use Instance.DescendantAdded to detect if a object was inserted.

game.DescendantAdded:Connect(function(object)
   -- do something
end)
2 Likes

You have to do game.workspace. Game is the parent of Workspace.

It is possible, I’ve done it before, but it is very easily bypassable and is certainly not recommended.

There isn’t really a difference of game.Workspace and workspace. They’re both the same thing.

1 Like

Wait, I thought this would prevent exploiters from instancing scripts(if you basically detect for every services) and remote events and local scripts right?

game.Players.PlayerAdded:Connect(function()
        game.Workspace.ChildAdded:Connect(function(child)
               if child:IsA("Script") then
                  child:Destroy()
            end
    end)
end)

They don’t have to create a script to execute code, they don’t have to insert anything as an Instance, therefore, it’s practically impossible to stop exploiters running code. The most you can do is protect your RemoteEvents with proper server-side checks and make server-side anti-cheat, e.g. flying. Even then, it can still be spoofed.

1 Like

Oh, so how do they run their code?

There are a few issues with this:

  1. The server cannot detect if exploiters inserts an object/instance, since it does not replicate to the server from the client.

  2. Exploiters run their code on the client-side, which means the classname would be LocalScript, not Script (not that it really matters in this scenario, as it’s a lost case).

  3. Exploiters don’t even need a LuaSourceContainer | Roblox Creator Documentation to run their exploit.


If you’re having issues with exploiters, at least state what you are trying to patch.

1 Like

Add this to a client script as exploits can only use client sided scripts.

game.workspace.ChildAdded:Connect(function(newPart)
	
	if newPart:IsA("Part") then
		players:Kick("You've been Kicked for Exploiting.")
	end
end)

am pretty sure its not possible if its added thru the client because you wont be able to detect it that would only run in the server so if you had a backdoor spamming audios you can delete it etc.