Does LocalScript run inside SurfaceGUI?

Hi, so I was working with RoProxy today and I made it working. Although I made a LocalScript inside SurfaceGUI which basically checks if any button was clicked and it should prompt the purchase, but it seems like nothing inside it works, even print().

local MPS = game:GetService("MarketplaceService")
local booth = script.Parent.Parent.Parent
local productsgui = booth.Products.SurfaceGui.ScrollingFrame
local connections = {}

productsgui.ChildAdded:Connect(function(child)
	if child:IsA("TextButton") then
		connections[#connections+1] = child.MouseButton1Down:Connect(function()
			MPS:PromptPurchase(game.Players.LocalPlayer, child:GetAttribute("Id"))
		end)
	end
end)

Is there anything wrong with this code or just LocalScript doesn’t run inside SurfaceGUI ? Also, if there’s any other way to achieve what I want, please let me know.
Thanks :slight_smile:

It depends where the SurfaceGui is located.
If it’s in a Part in workspace then no - a localscript will not work so just change it to a regular script.
If for some reason you need the script to be local then you can move the gui to StarterGui and set the Adornee to the part in workspace.

Hmm, that is afterwards maybe complex. I just want to check who clicked the button. That’s why I made the LocalScript. Do you know how to actually check who clicked the button, using Script ?

I’m not sure it’s possible to get the player who clicked the button from a server script - at least not easily.
All you need to do is move the SurfaceGui from the Part which it’s currently in (example workspace.Part), put it into your StarterGui and in the Properties of SurfaceGui you will see one called Adornee - Click on this and then click on the part the gui was originally in (workspace.Part) - now you can use local scripts.

1 Like

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