Need help with MouseButton1Down Error

First Problem Fixed (Read Post 6 For Second)

Hello! I am trying to make a script that when a button is pressed, prompts the purchase of a gamepass. However, it seems that line 12 is erroring and causing the script not to work.

The Code (Just the error part the error is second line):

local VipGamepass = 12424604

VipButton.MouseButton1Down:Connect(function()
	local success, message = pcall(function()
		hasPass = MarketplaceService.UserOwnsGamePassAsync(player.UserId, VipGamepass)
	end)

	if hasPass then
		print("Player Already Has VIP Gamepass")
	else
		MarketplaceService:PromptGamePassPurchase(player, VipGamepass)
	end
end)

The error:

  21:33:53.296  MouseButton1Down is not a valid member of Frame "Players.NotAid_n.PlayerGui.shop.Shop.ScrollingFrame.VIPgamepass"  -  Client - ShopScripts:12
  21:33:53.297  Stack Begin  -  Studio
  21:33:53.297  Script 'Players.NotAid_n.PlayerGui.shop.ShopScripts', Line 12  -  Studio - ShopScripts:12
  21:33:53.297  Stack End  -  Studio

From the error, it looks like your referencing to a frame, not a button, can you take a picture of the explorer where the GUI is?

1 Like

Your problem is that the object VIPButton is actually a frame. Frames do not have a MouseButton1Down event. You would have to switch your frame out for a button.

This is your problem. “VIPgamepass” should be a button. Either a “TextButton” or an “ImageButton” depending on how you want it to look. The alternative would be to add a button inside of the Frame and reference to that.

1 Like

Okay, now I have another problem! (likely having to do with this scripting)

OpenShop.MouseButton1Down:Connect(function()

MainFrame.Visible = not MainFrame.Visible

end)

CloseShop.MouseButton1Down:Connect(function()

MainFrame.Visible = not MainFrame.Visible

end)

For some reason its only opening half the time! The CloseShop button works fine but the OpenShop button is giving me issues.


@Pr0pelled

What are the two variables referencing?

Are “CloseShop” and “OpenShop” the same button?

no here are the variables:

local OpenShop = script.Parent.openclose -- "Click The Button To 
-- Close/Open This is the one im having trouble with.
local CloseShop = script.Parent.Shop.close -- "X" To Close

You should change each .MouseButton1Down to .MouseButton1Click.
The previous one only works with the click held, if you do it quickly it does not work

That doesnt work at all. It just changes the way of clicking it still doesnt pop up when clicked. (so i dont think the .MouseButton1Down Part is the problem)

You definitely want click instead of down. Since you know one is open and the other is close, set the Visible explicitly to true and false for open and close instead of using not.

I want it to be able to be multi-purpose. Also, I have heard Down is way better than click for many reasons. That is clearly not addressing the problem. Also, I tried that and it doesnt work.

Might something be covering up the open/close UI? Possibly when you open the shop, the shop UI covers up the open/close button which would block it from being clicked.

I found out why, it was for some reason only working when the text was clicked instead of the whole button. Thanks everyone who tried to solve it!

Yup basically it was only covering a small section of the button lol

One thing im still confused about is why, it should work normally the text isnt even mentioned.

If you have something covering up the button, then it is obstructing the button. When you click, the click is not recieved by the button because you are technically clicking whatever is on top of it.

1 Like

That was my next guess. Looking at your explorer tree. I assume the image and text that are children of openclose are on top of the button. They would block the click. You would want to put a transparent button on top of them with a higher Z order to catch all clicks.

To follow up with this, I noticed you had a “TextLabel” inside of the button, That shouldn’t be necessary, you should set the “TextButton.Text” to whatever text you want.

I went ahead and made a seperate event for the things within the button as well. that should fix it.