Attempt to index function with 'MouseButton1Click'

So I’ve never seen this error before and I can’t find it using a Google search, so I’m coming here. I have some buttons on a GUI and they are supposed to do things when they are clicked. The code below is where this is coming from.

local queue = script.Parent.Container:WaitForChild('Queue')
queue.Background.Buttons.Remove.MouseButton1Click:Connect(function()
	for i,v in pairs(selection) do
		function call(id)
			getqueue()
		end
		qs:remove(game.Players.LocalPlayer, v.SongId, call)
		table.remove(selection, i)
	end
end)

When I load into the game, I get this error:
13:14:37.547 - Players.Golembyte.PlayerGui.MusicQueue.Runner:56: attempt to index function with 'MouseButton1Click'

Again, I have never seen this error and I don’t know why it’s doing this. It’s supposed to let me click it and the code runs.

1 Like

Remove is also the name of a function used to remove an object. I suggest renaming it, that might help avoid this issue.

11 Likes

There’s an old deprecated function called :Remove(), it’s trying to index that with it. You can either change it to

...Buttons:FindFirstChild("Remove").MouseButton1Click

or just change the name.

2 Likes