MouseButton1Click not registering

Hello,
I am trying to make a script that will project more details onto a new UI frame when specific UIs are clicked for a tower defense game, such as the cost of towers and an enlarged form of a viewport.
The problem is that it doesn’t detect the clicks at all, I tried inserting a print into the loop as well, and I found that it just was not registering the clicks. There were no errors in the code either and the Output had nothing. Here is the code, as well as an image of the object browser in case that yields anything:

local detailname = script.Parent.Parent.Parent.Parent.Details.TowerName
local detailcost = script.Parent.Parent.Parent.Parent.Details.TowerCost
local detailessence = script.Parent.Parent.Parent.Parent.Details.TowerEssence
local detailvp = script.Parent.Parent.Parent.Parent.Details.ViewportFrame
local detailpurchase = script.Parent.Parent.Parent.Parent.Details.Purchase
local towerbtn = script.Parent.Button
local towertext = script.Parent.Button
local towervp = script.Parent
local towercam = script.Parent.Parent.Camera
local tower = script.Parent.Tower
local toweroverlay = script.Parent.OverlayButton
local function refresh ()
	print("button pressed")
	detailname.Text = towertext.Text
	detailcost.Text = "0"
	detailessence.Text = "30 Essence"
	detailvp.CurrentCamera = towercam
	local towerclone = tower:Clone()
	towerclone.Parent = detailvp
	detailpurchase.Text = "Owned"
end
towerbtn.MouseButton1Click:Connect(refresh)
toweroverlay.MouseButton1Click:Connect(refresh)


Sorry for insane amount of local variables and “.parents” as well.
I don’t think the issue is ZIndex, as for testing I tried pushing all of the relative buttons (TowerOverlay and Towerbtn) to a big ZIndex and pushing all unrelated UI objects to a low ZIndex as well.

Wait so the text button is in the viewport frame? why do you need it like that?

Is there any way to keep the text button outside of this frame?

1 Like

The UIGridLayout puts them all side by side instead of in the fashion they are meant to be in. Is there a way to bypass UIGridLayout?

My Friend uses grids and stuff all the time I think he just puts the UI in folders if he doesn’t want them effected.

1 Like

OK, I’ll see if that helps the situation.

Oof, the folders did work, but sadly it still doesn’t register the clicks.

hmm maybe try sending a picture of properties? I think Active might just be the only thing to look at though. If thats off it just doesnt send events to it.

1 Like

I turned active on for all objects and frames, still nothing. Also, doesn’t .Active mean that you can click into 3D objects beneath UI objects?
If you still want the properties, of which object do you want it for?

Oh no you dont need active for everything, but Active just enables events for GUI objects ( at least thats what the textbutton in my game is telling me xD )

I dont think i need the properties, but is that all thats in the Local Script?

1 Like

yes, thats all thats in the local script.

Maybe try moving the local script out of the viewport frame ( err so you dont mess up all of your code just make a new script inside the button and print on click )

1 Like

I made a local script under the buttons and made it print stuff, and it worked! Now all I have to do is copy the code over and change it up a little. I’ll let you know if it works.

1 Like

Sweet! It probalby wasnt running because it was under a viewport frame lol

1 Like

When I inserted the script into it, it didn’t work ):
No errors in the output either.
It’s the same code, I just changed the path of the local variables to match.

Uhh I dont know what the issue is. I just tested some examples I was able to get each button to work even the ones inside viewport frames + scripts work there too

1 Like

You dont have any Yields or anything right? I can only assume the script is disabled or waiting for something to happen for no errors to occur, but also with nothing working.

1 Like

aha! I found the error! I just had to scroll way up in the output, my bad entirely! It says
“11:39:39.190 Camera is not a valid member of Folder “Players.ValtryekRBLX.PlayerGui.ScreenGui.ShopFrame.ScrollingFrame.ObjHolder.Mage” - Client - LocalScript:8”

1 Like

:smile: Well thats good news I had no idea how it was possible

1 Like

How would you fix this then, because Camera is a direct child of Folder.
Should I just use :WaitForChild()?

Yeah I assume its just not loading into the world fast enough for the script to find it

1 Like