Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make this GUI give the players their choices to buy a shirt?

Asked by 9 years ago

I am having trouble with a GUI that allows a player to choose their logo and color which would direct them to buy the shirt with those options. However, I am stuck at this process. How would you do it? Here's how they are placed:

ShopGui > Shirts (Frame) > Design1, Design2, Textures(frame) > Texture1, Texture2, Open/Close (button)

Here's the localscript that will be used inside Design1 and Design 2:

local design = script.Parent
local sframe = script.Parent.Parent
local gui = sframe.Parent

design.MouseButton1Down:connect(function()
    if design then
        gui.Textures.Visible = true
        sframe.Visible = false
    end
end)

Here's the localscript that will be used inside Texture1 and Texture2:

local texture1 = script.Parent
local player = game.Players.LocalPlayer
local marketplace = game:GetService("MarketplaceService")
local shirt =  -- I know there's more than just one shirt but idk what to do in this case

texture1.MouseButton1Down:connect(function()
    marketplace:PromptPurchase(player,shirt)
end)

In case you need the open/close localscript:

local button = script.Parent
local display1 = button.Parent.Shirts
local display2 = button.Parent.Textures


button.MouseButton1Down:connect(function()
 if display1.Visible and display2.Visible then

    display1.Visible = false
    display2.Visible = false
else
    display1.Visible = true
    display2.Visible = false
end
end)

1 answer

Log in to vote
0
Answered by 9 years ago

First, you do not need to have the shirt variable set right away (you can simple put local shirt without the equal sign), you can have the MouseButton1Down event handler return if the shirt is not set: if shirt == nil then return end

A good solution could be to have a table that links colors and logos to their shirt:

local shirt = {
    ['1,0,0'] = {
        logo1 = "red logo1 asset",
        logo2 = "red logo2 asset"
    },
    ['0,1,0'] = {
        logo1 = "green logo1 asset",
        logo2 = "green logo2 asset"
    }
}

local function colorToString(color)
    return tostring(color.r) .. "," .. tostring(color.g) .. "," .. tostring(color.b)
end

local function getTemplateByColorAndLogo(color, logoName)
    return shirt[colorToString(color)][logoName]
end

Next you will need some buttons to set the color and logo name. How you do this depends on your design.You can have functions handling which button is pressed and then have it set a variable for the color and logo (then you could have the MouseButton1Down event handler get the shirt using those variables if they are set).

0
What are ['1,0,0'] and ['1,1,0'] used for? Darknesschaos 0 — 9y
0
The ['1,0,0'] and ['0,1,0'] represent r, g, and b color values (if you are using a Color3 value). cjcool12345 58 — 9y
Ad

Answer this question