Can't pass Instance in module script function

in the choosePoints() function, when I connect the function ButtonClicked, and pass the button clicked as a parameter, when recieving it in the ButtonClicked function, for some reason it is nil, even though in the choosePoints() function, it is an instance (I checked using typeof() )

choosePoints function

local function choosePoints(player)
	local Point = "rbxassetid://16970513466"
	local Node = "rbxassetid://16970777248"
	local playerButtons= player.PlayerGui.KeypadUI.Frame.Frame
	local layoutChosen = layouts["layout"..math.random(1,11)]
	local indexnum = 1
	repeat
		task.wait()
		layoutChosen = layouts["layout"..math.random(1,11)]
	until layoutChosen
		for counter = 1,64 do
			if counter == layoutChosen[indexnum] then
				local imageButton = Instance.new("ImageButton")
				imageButton.Parent = playerButtons
				imageButton.Image = Point
				imageButton.BackgroundTransparency = 1
				local isPoint = Instance.new("BoolValue")
				isPoint.Name = "isPoint"
				isPoint.Parent = imageButton
				isPoint.Value = true
				local coordinate = Instance.new("IntValue")
				coordinate.Name = "coordinate"
				coordinate.Value = counter
				indexnum = indexnum + 1
				local colourTable = layoutChosen[indexnum]
				imageButton.ImageColor3 = colourTable[1]
				table.insert(colourTable, imageButton)
				table.insert(all, imageButton)
				indexnum = indexnum + 1
				print(typeof(imageButton))
				imageButton.MouseButton1Click:Connect(buttonClicked, imageButton)
			else
				local imageButton = Instance.new("ImageButton")
				imageButton.Parent = playerButtons
				imageButton.Name = "Normal"
				imageButton.Image = Node
				imageButton.BackgroundTransparency = 1
				imageButton.ImageColor3 = Color3.new(0.619608, 0.619608, 0.619608)
				local isPoint = Instance.new("BoolValue")
				isPoint.Name = "isPoint"
				isPoint.Parent = imageButton
				isPoint.Value = false
				table.insert(normal, imageButton)
				table.insert(all, imageButton)
				print(typeof(imageButton))
				imageButton.MouseButton1Click:Connect(buttonClicked, imageButton)
			end
			
		end
	return true
end 

part of the ButtonClicked() function (its a little bit long, and I don’t think any of it is relevant to this bug, if you want to see it just ask

local function buttonClicked(button)
	print(typeof(button))
	local cornerImage = "rbxassetid://16970742131"
	local straightImage = "rbxassetid://16970479458"
	local halfLineImage = "rbxassetid://16992462898"
	local pointLineImage = "rbxassetid://16992466398"
	local function findColour()
		for i,ColourTable in pairs(colours) do
			for i,v in ipairs(ColourTable) do
				if v == button then
					if v.Name == "isPoint" then
						return true, ColourTable
					end
					return false, ColourTable
				end
			end
		end
		return false, nil
	end

imageButton.MouseButton1Click:Connect(buttonClicked, imageButton)
you can’t pass parameters like that as far as i’m aware. You have to do the following:
imageButton.MouseButton1Click:Connect(function() buttonClicked(imageButton) end)

1 Like

You’re passing two arguments to buttonClicked, but it only accepts one Adjust buttonClicked to accept only one argument

-- Remove the second argument from buttonClicked
local function buttonClicked(button)
    -- Your code here
end

-- Connect with only one argument 1!
imageButton.MouseButton1Click:Connect(buttonClicked)
2 Likes

As far as i’m aware, MouseButton1Click doesn’t pass the button as an argument by itself.

1 Like

thanks, I switched it to

imageButton.MouseButton1Click:Connect(function()
   buttonClicked(imageButton)
end)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.