MouseButton1Clicked event failing to connect

Hello, I’m creating a Gui and I have this ImageButton with no image as a selection frame. But I have a problem with it, and that is, it’s always setting the position to {0,0},{0,0}.

Script:

-- Services
local RepStorage = game:GetService("ReplicatedStorage")
local ContentProvider = game:GetService("ContentProvider")
-- Variables
local MainFrame = script.Parent
local remote = RepStorage.RemoteEvents.ValueChanger
local maps = RepStorage.Maps:GetChildren()
local assets = {}
-- URL
local baseURL = "rbxassetid://"
-- Loop
for i, v in pairs (maps) do
	table.insert(assets, i, baseURL..(v.ImgId.Value))
end
spawn(function()
ContentProvider:PreloadAsync(assets)
end)
for i, v in pairs (maps) do
	local Frame = Instance.new("Frame", MainFrame)
	Frame.Name = v.Name.." Map"
	Frame.BackgroundColor3 = Color3.fromRGB(72, 72, 72)
	Frame.Size = UDim2.new(0.13, 0,0.329, 0)
	Frame.ZIndex = 10
	local Text = Instance.new("TextLabel", Frame)
	Text.BackgroundTransparency = 1
	Text.Font = Enum.Font.GothamBold
	Text.TextScaled = true
	Text.Name = "MapName"
	Text.Text = v.Name
	Text.Size = UDim2.new(1, 0,0.306, 0)
	Text.Position = UDim2.new(0, 0,0.653, 0)
	Text.ZIndex = 15
	local ImgLabel = Instance.new("ImageLabel", Frame)
	ImgLabel.Size = UDim2.new(1, 0,0.694, 0)
	ImgLabel.Image = baseURL..(v.ImgId.Value)
	ImgLabel.ZIndex = 15
	ImgLabel.Name = "Image"
	local selectionFrame = Instance.new("ImageButton", Frame)
	selectionFrame.BackgroundTransparency = 1
	selectionFrame.Size = Frame.Size
	selectionFrame.Position = Frame.Position
	selectionFrame.ImageTransparency = 1
	selectionFrame.ZIndex = 20
	selectionFrame.Name = "SelectionFrame"
	selectionFrame.MouseButton1Click:Connect(function()
		remote:FireServer("SelectedMap", v.Name)
	end)
	Frame.LayoutOrder = i
end
1 Like

I mean creating a new Frame, the automatic position is going to be {0,0},{0,0} so probably change this Frame’s position since you are redirecting the position of the ImageLabel to this Frame’s position or change it manually, here is an instance:

selectionFrame.Position = UDim2.new(0.5,0,0.5,0)

I’ve already done that as you can see.

1 Like

Frame’s position hasn’t been set either, so it also defaults to {0,0},{0,0}.

Therefore, you are still setting the selectionFrame’s position to {0,0},{0,0}.

Edit: You said it’s not functioning as intended and the position {0,0},{0,0} is the problem, what are you trying to accomplish?

I’m trying to make a map selection Gui and all maps in the folder will automatically go there so I’ll never have to update this Gui.

I just recognized that yes, it’s 0,0 in first one too but nothing happened when I click so I thought it’s because of the position.

It might be an issue with MouseButton1Click. I would try changing that to MouseButton1Down and see if the result changes at all.

It may also be worth reading this topic:

I’ll test it later and write the results here.

1 Like

Sorry for being late.

I tried it, but it didn’t work. It runs all other code but it can’t connect the event.
Explorer:
image
We can see that everything is generated.

(No errors on output)

Did you find any solution? I have the same issue and I am 100% sure it’s not something related to coding because I am just trying to print a value and its neither printing nor giving any error. My text Button is active and selectable.

Unfortunetaly, no, I haven’t. I left this project a while ago by the way.

1 Like