My Issue: Lacking Permission
My Goal: Make a Plugin
My Script Type: Local Script
My Code:
local Selection = game:GetService("Selection")
script.Parent.FocusLost:Connect(function(Enter)
if Enter then
local FoundTable = {}
for i, _ in pairs(game:GetDescendants()) do
if string.match(_.Name:lower(), script.Parent.Text:lower()) then
table.insert(FoundTable, _)
end
end
Selection:Set(FoundTable)
end
end)
I am trying to make a plugin but I am using a Gui Textbox so I can search for items to select. For eg: I will search “Baseplate” in the textbox and the textbox will select every item in the game named “Baseplate”
You probably get the lacking permission error because your code cycles through every instance in the game, which also includes core scripts in the CoreGui, which you’re not allowed to tamper with. If you really must use :GetDescendants(), wrap it in a pcall to avoid errors.
local Selection = game:GetService("Selection")
script.Parent.FocusLost:Connect(function(Enter)
if Enter then
local FoundTable = {}
for i, _ in pairs(game:GetDescendants()) do
pcall(function()
if string.match(_.Name:lower(), script.Parent.Text:lower()) then
table.insert(FoundTable, _)
end
end)
end
Selection:Set(FoundTable)
end
end)
I think the main reason is I have to use it in a plugin, which means I cannot select things in the game via script. I will keep your code inside my script and try it out when it is a plugin and see what I get.(When I ran the code while it was a plugin, it worked)