Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Attempt to index function with 'MD'? [SOLVED]

Been stuck on this for a while now. I'm trying to connect a function to an event, but i get error "attempt to index function with 'MD'". Didn't find any helpful info on this error. Here is my code:

local SearchGUIs = script.Parent:WaitForChild('SearchGUIs') -- WaitForChild to prevent loading error
local QuickSearch = script.Parent:WaitForChild('QuickSearch') -- WaitForChild to prevent loading error
local FilterButtons = script.Parent:WaitForChild('FilterButtons') -- WaitForChild to prevent loading error
local IGR = game.ReplicatedStorage:WaitForChild('IssueGetRequest') -- WaitForChild to prevent loading error
local IPR = game.ReplicatedStorage:WaitForChild('IssuePostRequest') -- WaitForChild to prevent loading error
local query = '*'
local filters = '?'
local letters = 0

local function QuickSearch(filter) -- Filter search
	local returned = IGR:InvokeServer('search/*?type='..filter)
	
	if returned[1] == 'Success' then
		for tI, tV in pairs(returned[2]) do
			print('Level info started')
			for i, v in pairs(tV) do print(i, v) end
			print('Level info ended')
		end
	else
		warn(returned[2])
	end
end

SearchGUIs.QueryBox.FocusLost:Connect(function()
	if SearchGUIs.QueryBox.Text == '' then
		query = '*'
	else
		query = SearchGUIs.QueryBox.Text -- Using a variable instead of the raw text, to change it to 'Enter text, user, or ID...'
		
	end
	
	SearchGUIs.QueryBox.Text = 'Enter text, user, or ID...'
end)

SearchGUIs.Search.MouseButton1Down:Connect(function(x, y) -- Level search
	print('Level search initiated')
	filters:sub(1, letters - 1)
	local returned = IGR:InvokeServer('search/'..query..filters)
	
	if returned[1] == 'Success' then
		for tI, tV in pairs(returned[2]) do
			print('Level info started')
			for i, v in pairs(tV) do print(i, v) end
			print('Level info ended')
		end
	elseif returned[2] == -1 then
		warn('Level not found!')
	else
		warn('Error: '..returned[2])
	end
end)

SearchGUIs.SFU.MouseButton1Down:Connect(function(x, y) -- Profile search
	print('Profile search initiated')
	local returned = IGR:InvokeServer('profile/'..query)
	
	if returned[1] == 'Success' then
		print('User info started')
		for i, v in pairs(returned[2]) do
			print(i, v)
		end
		print('User info ended')
	elseif returned[2] == -1 then
		warn('User not found')
	else
		warn(returned[2])
	end
end)

-- Quick search

QuickSearch.MD.MouseButton1Down:Connect(function(x, y) QuickSearch('mostdownloaded') end)
QuickSearch.ML.MouseButton1Down:Connect(function(x, y) QuickSearch('mostliked') end)
QuickSearch.Awarded.MouseButton1Down:Connect(function(x, y) QuickSearch('awarded') end)
QuickSearch.Featured.MouseButton1Down:Connect(function(x, y) QuickSearch('featured') end)
QuickSearch.Magic.MouseButton1Down:Connect(function(x, y) QuickSearch('magic') end)
QuickSearch.Recent.MouseButton1Down:Connect(function(x, y) QuickSearch('recent') end)
QuickSearch.Trending.MouseButton1Down:Connect(function(x, y) QuickSearch('trending') end)

Any help is appreciated!

2 answers

Nevermind, I'm creating two variables with the same name, one is an instance, the other is a function.

The solution is to rename the function.

When connecting a function to an event, use this:

QuickSearch.Recent.MouseButton1Down:Connect(QuickSearch('magic'))

It runs the function automatically. If that doesn't work, then I assume it's something to do with your function code.

Hope this helped!

3 comments

0

When using :Connect(), I can't define my own arguments.

0

Ah, I see.

0

Just realised this applies to any functon which accepts a function as an argument, inclusing game.ContextActionService:BindAction()

This discussion is preserved as it was. New answers, comments, and votes are closed.