Attempt to call 'a' Instance value

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 :slight_smile:

2 Likes

I believe I know the problem. You see, when you mention the variable descendantsOnly, you say .Descendants, where the appropriate term would be :GetDescendants

This goes for the variable childrenOnly too.

Ah, that is not the problem. I am referencing bool values by those names. I’ll send you the explorer in a bit.

Here’s the explorer for reference:


NOTE: AnchorSetter and CollisionSetter are basically the same as TransparencySetter

Is selection a table or instance?
To check, you should do print(typeof(selection))

There you have it mate, selection:Get() returns a table, so here you go. If you’re a bit confused, check’s 4th argument (get) is a table, so since selected is a table, it should work.

1 Like

Found the issue. So, in the function check, I see it checks if descendants is not nil, elseif the children, else parent. Well, the issue is you are checking if descendants then because of the lack of “FindFirstChild” instead using dots. FindFirstChild returns a value, dots tend to break code.

Source of issue:

Replace dots with FindFirstChild^
Should probably do it for parentOnly too if applicable.

I used it on parentOnly because I knew what would happen, I’ll try this in a bit
EDIT: @iiSkyWarrior805 It didn’t work, I got the same error

I read all code top to bottom, afraid my problem solving skills are irrelevant now, sincere apologies.

Understood how you said your code has been working the way it should, which leaves me to my next question. My final question to you, are Studio Beta features toggled on? If so, should probably disable them too.

I never said it was working, anyways the only beta features I have on are Pivot Editor and something about terrain, I don’t think that was the problem either.

descendants is a function
you’re using “descendants” as parameter on the function “check” so it overwrites

Slight off-topic
I had a friend who’s custom Animate script broke because it happened so suddenly, turns out it was Beta features were toggled on. It fixed after they toggled it off. It will not hurt to try?

function check(descendantsa, children, parent, selected)
	if descendantsa then
		return descendants(selected) --LINE 53 HERE
	elseif children then
		return children(selected)
	else
		return parent(selected)
	end
end

replacing the check function with the one above should fix your error

I didn’t know that it would happen like that! Thank you for your help :slight_smile: .