Yes, I checked other resources, including the guide to Interactive Surface GUI but I’m still not finding a solution to my problem. What I tried is to use a Local Script and put it in StarterGui, which detects if the button on the Workspace if clicked, but it did not work.
The problem: I cannot figure out a simplified way to make a clickable TextButton within a SurfaceGui.
Here’s the picture of the clickable TextButtons (Buy Shirt and Buy Pants):
I plan to use this model multiple times (as in I will clone them for different set of shirt and pants). Now, from what I read, I need to put the SurfaceGui on StarterGui and set the adornee to the individual part.
This will just be too much if I have to clone them (imagine having to clone 20 SurfaceGuis for 10 boards, since the SurfaceGui are on both and back sides of the model (10 boards x 2 sides)).
I prefer a solution that you can click the TextButton, then a script detects it. However, this presents the problem that Server Script won’t know who clicked it (local player doesn’t exist in server script), so I won’t be able to prompt purchase.
Prompting the purchase has to come from the client and not the server.
--Put this in a local script within the button!
local MPS = game:GetService("MarketplaceService")
local player = game.Players.LocalPlayer
local shirtId = --Put your shirt/Pants id here
local Button = script.Parent
Button.MouseButton1Click:Connect(function()
game:GetService("MarketplaceService"):PromptPurchase(plr, shirtId) -- This will prompt the purchase
end)
Place all of your models into a folder or another model and then in a LocalScript you should clone, parent, and set the Adornee on a SurfaceGui for each model using a for loop.
Did you try to understand my problem or not at all? I’m definitely fine if I had to change the way how this will work for the sake of simplicity.
Obviously, I need to solve for the problem, and there’s no need to worry about the prompts yet. If I really have to restate the problem again, here it is: I cannot figure out a simplified way to make a clickable TextButton within a SurfaceGui in a model that will be used more than once.
The previous person suggested using a for loop to duplicate the GUI and set adornee one by one to each model, that sounds more like it. But the problem with that is each single model will have different shirt and pants ID.
The “clickable” part makes your problem sound totally different as if you’re wanting to make a Text Button Clickable to prompt a purchase. But I still apologise.
Like the previous user said, you have to make an iteration probably by using the command bar to clone your stuff and just change the adornee. Regarding the IDs of shirts and pants I don’t see any possible shortcuts, you have to input them one way or another. What I would do just to make it better is to make use of StringValues for ShirtId and PantsId in each surface gui and change them while making the local script of the prompt use these two so you don’t have to change anything in the script. Changing StringValues is easier probably.
And yes you will still have a lot of surface guis but I don’t see a problem with that, just make use of folders to keep it organised.