Once again I’m fixing my plugin but as usual, things aren’t so simple. I keep getting the error ‘Attempt to call a Instance value’ (wrong grammar lol) on line 53 when testing my new function that is (supposed to) make my code simpler. Here’s my entire code:
print("Plugin Status: Running")
--Services
local selection = game:GetService("Selection") --selection
local IS = game:GetService("InsertService")
--local Model = IS:LoadAsset(ID)
local CHS = game:GetService("ChangeHistoryService")
print("Services Variables Loaded")
--GUI Variables
local gui = script:WaitForChild("PartEditor") --Gui
local open = false --Is not opened
local descendantsOnly = gui.Settings.Descendants
local childrenOnly = descendantsOnly.Parent.Children
local parentOnly = childrenOnly.Parent:WaitForChild("Parent")
local chosen
local transparencybutton = gui:WaitForChild("TransparencySetter"):WaitForChild("SetTransparency") --transparency setter
local transparencytextbox = transparencybutton.Parent.ValueBox
local anchorbutton = gui:WaitForChild("AnchorSetter"):WaitForChild("SetAnchor") --anchor setter
local anchortextbox = anchorbutton.Parent.ValueBox
local collisionbutton = gui:WaitForChild("CollisionSetter"):WaitForChild("SetCollision") --collision setter
local collisiontextbox = collisionbutton.Parent.ValueBox
print("GUI Variables Loaded")
--Functions
function parentsOnly(selection)
return selection
end
function descendants(selection)
local contents = {}
for i, v in pairs(selection) do
local descendants = v:GetDescendants()
table.insert(contents, descendants)
end
return contents
end
function children(selection)
local contents = {}
for i, v in pairs(selection) do
local children = v:GetChildren()
table.insert(contents, children)
end
return contents
end
function check(descendants, children, parent, selected)
if descendants then
return descendants(selected) --LINE 53 HERE
elseif children then
return children(selected)
else
return parent(selected)
end
end
function doWhatever(chosenProperty)
if chosenProperty == "Transparency" then
local get = selection:Get()
local check = check(descendantsOnly, childrenOnly, parentOnly, get)
local num = tonumber(transparencytextbox.Text)
local bool = anchortextbox.Text
if num then -- checking to see if the text was converted successfully
if num >= 0 and num <= 1 then -- flipped the signs
for i, part in pairs(get) do
if part:IsA("BasePart") then
if parentOnly then
if part:IsA("BasePart") then
part.Transparency = num
end
elseif descendantsOnly or childrenOnly then
for i, descendant in pairs(check) do
if part:IsA("BasePart") then
part.Transparency = num
end
end
end
end
end
else
print("There was an error, try again.")
end
elseif chosenProperty == "Anchored" then
if bool then
if bool == "true" then
if parentOnly then
for i, part in pairs(get) do
if part:IsA("BasePart") then
part.Anchored = true
end
end
elseif descendantsOnly or childrenOnly then
for i, part in pairs(check) do
part.Anchored = true
end
end
end
elseif bool == "false" then
if parentOnly then
for i, part in pairs(get) do
if part:IsA("BasePart") then
part.Anchored = false
end
end
elseif descendantsOnly or childrenOnly then
for i, part in pairs(check) do
part.Anchored = false
end
end
end
else
print("There was an error, try again.")
end
end
end
--Plugin Creation
local toolbar = plugin:CreateToolbar("Part Editor")
local newScriptButton = toolbar:CreateButton("EditPartEasily", "A better way to edit parts!", "rbxassetid://157942894", "Part Editor")
newScriptButton.Click:Connect(function()
if open == false then
gui.Parent = game:GetService("CoreGui")
open = true
gui.Core.Visible = true
else
gui.Parent = script
open = false
gui.Core.Visible = false
end
end)
--Connected Events
transparencybutton.MouseButton1Click:Connect(function() --tried moving this event to a local script, didn't work
chosen = "Transparency"
doWhatever(chosen)
end)
anchorbutton.MouseButton1Click:Connect(function() --tried moving this event to a local script, didn't work
chosen = "Anchored"
doWhatever(chosen)
end)
collisionbutton.MouseButton1Click:Connect(function() --tried moving this event to a local script, didn't work
print("Button pressed, Server")
chosen = "Collision"
local get = selection:Get()
local bool = collisiontextbox.Text
if bool then
if bool == "true" then
for i, part in pairs(get) do
if part:IsA("BasePart") then
part.CanCollide = true
end
end
elseif bool == "false" then
for i, part in pairs(get) do
if part:IsA("BasePart") then
part.CanCollide = false
end
end
end
else
print("There was an error, try again.")
end
end)
(Apologies for the messy indentation) Thanks for your help