MouseButton1Click Problem

I am creating a simple button to prompt a product purchase but the MouseButton1Click does not seem like working. I could not find any thing that I understand which could solve it. The local script’s parent is a text buttons . The parent of the text button is just a frame and the frame’s parent is a surface gui and the frame’s children are 5 other textbuttons and a text label all not overlapping

local mps = game:GetService("MarketplaceService")
local product = 1086223418
local player = game:GetService("Players")
local plr = player.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
	print(script.Parent.." has been clicked")
	mps:PromptProductPurchase(plr,product)
end)

Edit: Changed the parent from frame to TextButton in the post because I typed it out wrongly.

Edit changed it to text buttons. Why do I keep mixing them up?

1 Like

You’re ham? Jokes aside, can you provide a picture of your gui and its property?

1 Like

You cannot use MouseButton1Click on a Frame. I recommend replacing it with a TextButton with no text.

2 Likes

A meant the frame is the parent of the text button

Attaching screenshot of your explorer that contains ancestry of your GUI might be a big help to find out your problem.

So the parent is a button or a frame?

I made Tutorial Video for that.

if you really want to use a frame, you can check if your clicking and if your clicking then check where the cursor position is. If it is on the frame then you trigger the function.
Or, just use a button because its well easier

Your printing an object, this may stop the code because you can’t print an object. Try script.Parent.Name

I am on mobile at the moment. But I clearly remember it. I will stack it in order

Part 
    SurfaceGui
        TextLabel
        TextBox1
        TextBox2
        Textbox3
        TextBox4
        Textbox5
        Textbox6
            Local Script

MouseButton1Click is not an event of TextBox either. It is an event of TextButton or ImageButton.

Has this given you any errors? Anything at all?

No, nothing has been printed in the output

Sorry, I edited the post again. I keep mixing them up

Can you quickly remove the print() and double check the productID, Making sure its word to word?

LocalScripts only run if they are in:

  • A Player’s Backpack , such as a child of a Tool
  • A Player’s character model
  • A Player’s PlayerGui
  • A Player’s PlayerScripts .
  • The ReplicatedFirst service
2 Likes

They can also run via MouseButton1Click event, when the script is a child of Textbutton and Imagebutton.

I’m assuming the SurfaceGui is in Workspace. Hence, the LocalScript is a descendant of Workspace, which means it won’t run.

Hmm, i think i found the problem.
If what @pwnion said is true, then that is the correct answer. However if it is in StarterGui, then I think you need to fire an event to the server when clicked, then copy and paste the productid and marketplaceservice in a Script. Dont send any data. Try it if it works.

So since it is in workspace, do I change it to a normal script?