How do I make this plugin work?

Hey again!

So right now I’m writing what is my first and probably my last plugin, It is supposed to change the scripts starting test to "print(“Hello world!”) to something else.

The error I am getting is:
image

My Code:

game.DescendantAdded:Connect(function(desc)
	if desc:IsA("Script") then
		if desc.Source == 'print("Hello world!")' or desc.Source == 'print("Hello World!")' or desc.Source == "print('Hello world!')" then
			desc.Source = [[-- File: 
				-- Author: wayIxn
				-- Description: 
				
				
				--// Services
				
				--// Variables
				
				--// Functions
				
				--// Other
								
				]]
		end
	end
end)

It is worth noting that when I run the script in the command bar it does not work, and I published it in a LocalScript in Workspace.

hi there!

the command bar, and scripts (scripts & localscripts), are not able to set the source of scripts, hence the message “lacking permission”

try making a plugin, that executes that code, then you should be able to do what the script is trying to do.

1 Like

That is what I’m doing. I have the plugin saved as a Local Plugin, and it isn’t working whatsoever.

You should pcall wrap the DescendantAdded call, as I believe you are picking up RobloxLocked instances.

2 Likes

okay, try wrapping it in a pcall, and make sure that the plugin script executing this code is a server script, not a localscript.

This will not have a bearing - plugin scripts share a common context.

That didn’t work, either. Heres my new script:

pcall(function()
	game.DescendantAdded:Connect(function(desc)

		if desc:IsA("Script") then
			if desc.Source == 'print("Hello world!")' or desc.Source == 'print("Hello World!")' or desc.Source == "print('Hello world!')" then
				desc.Source = [[-- File: 
					-- Author: wayIxn
					-- Description: 
					
					
					--// Services
					
					--// Variables
					
					--// Functions
					
					--// Other
									
					]]
			end
		end
	end)
end)

No - wrap inside the event connection. This should perform as expected.

2 Likes

That seemed to have worked, but now my script doesnt work, It didn’t in the first place either. I’m not great with plugins so I’m not sure how to fix that either.

are you able to post the part that is erroring, if any?

No errors are popping up, the script doesnt work, but the part that was wrapped in a pcall however, did fix my erroring problem.

okay, so that script (first post), is the whole plugin script?

My script now is:

game.DescendantAdded:Connect(function(desc)
	local s, e = pcall(function()
		if desc:IsA("Script") then
			if desc.Source == 'print("Hello world!")' or desc.Source == 'print("Hello World!")' or desc.Source == "print('Hello world!')" then
				desc.Source = [[-- File: 
					-- Author: wayIxn
					-- Description: 
					
					
					--// Services
					
					--// Variables
					
					--// Functions
					
					--// Other
									
					]]
			end
		end
	end)
end)

About to see if there are errors in the pcall, though.

Alright, same error even with the pcall.
image

game.DescendantAdded:Connect(function(desc)
	local s, e = pcall(function()
		if desc:IsA("Script") then
			if tostring(desc.Source) == 'print("Hello world!")' then -- those diffrent types of print are unneeded, I think that studio only uses print("Hello World!"), correct me here if I am wrong.
				desc.Source = [[-- File: 
					-- Author: wayIxn
					-- Description: 
					
					
					--// Services
					
					--// Variables
					
					--// Functions
					
					--// Other
									
				]]
			end
		end
	end)
end)

okay, try this.

1 Like

Nope, not sure whats wrong but it was just an experiment either way, thanks though! :slight_smile: