Plugin can't find the child of a part

Hello, I work with a game that constantly needs tweaking for its battles, but it uses a separate script for each battle, so I had to modify a different script, and use the console to replace them all, but It kept taking too much time, so I took the console commands, and put it into a plugin, but it can’t find the children of the parts, yet using the console it worked just fine.
image
image


local button = toolbar:CreateButton("Replace Battle Script","Replaces The Battle Script","http://www.roblox.com/asset/?id=5831578939")

button.Click:Connect(function()
	for i,v in pairs(game.Workspace:GetChildren()) do 
		if v.Name == "Battle" then 
			wait()
			v.Script.Battle.Parent = v
				wait()
			v.Script:Destroy()
			wait()
			local s = game.Workspace.Script:Clone()
			s.Parent = v
			s.Disabled = false
			wait()
			v.Battle.Parent = s		
		end
	end
end) ```

I’d try…

v:FindFirstChild("Script").Battle.Parent = v

That should work if I’m not mistaking.

I already tried, then it said Battle isnt a valid member of script.

Well, if it got that far you’d do the same thing to find Battle.

v:FindFirstChild("Script"):FindFirstChild("Battle").Parent = v

I also tried that, then it said “tried to index nil with findfirstchild”

I copied you code and it worked for me, not really sure why it isn’t for you. Here’s my code:

 local toolbar = plugin:CreateToolbar("Custom Script Tools")
local button = toolbar:CreateButton("Replace Battle Script","Replaces The Battle Script","http://www.roblox.com/asset/?id=5831578939")

button.Click:Connect(function()
	for i,v in pairs(game.Workspace:GetChildren()) do 
		if v.Name == "Battle" then 
			wait()
			v.Script.Battle.Parent = v
			wait()
			v.Script:Destroy()
			wait()
			local s = game.Workspace.Script:Clone()
			s.Parent = v
			s.Disabled = false
			wait()
			v.Battle.Parent = s		
		end
	end
end)

Proof that it is working:

Edit: Just noticed that you’ve possibly named your plugin script “Battle”. If you have and published it in Workspace it would be getting confused with your script importing and the script you’re wanting to get to.

I found out what happened, I did this right after tweaking it, and I pressed Control X instead of Control C for one of the battles, my bad. Tried it again, and it worked

1 Like