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

for shop script, after cloning and moving an item to screenGui card duplicates?

Asked by 6 years ago

Please read this, I know its long but i'm pretty desperate. Also i'm a beginner so understand my methods may not be the smartest way of solving my problems.

I am so confused... I need help with this shop script I built, which activates when a player clicks on a mannequin's shirt. When clicked, the script will bring up a prompt asking you to store it into cart. If you press yes, the script will copy the shirtID from the mannequin and paste it to a virtual 'card' which then takes that ID, gets the information from the product, then displays information about the shirt(name, price, thumbnail) within text labels in its 'card.' This card will go inside a virtual cart where players can store their cards before wanting to buy, try on, or delete the shirt in the card. (buying, trying on, and deleting items from the cart have not been scripted yet)

Two problems are showing up.

One thing. When you press yes the first time on a shirt, everything works normally. But if you press yes on that same shirt or another shirt, duplicates of each shirt added to cart appear. (ex. if you click yes on a shirt the first time, one shows up in cart, but if you click yes on that same shirt or another shirt, multiple duplicates of both selected shirts show up in cart.) What I want is simply for 1 shirt to appear after clicking on it, then another shirt after clicking on that. I don't know what I did wrong but hopefully you might.

Second thing. When I press play in my place, outside of RobloxStudio, none of the scripts having to do with clicking in a GUI work? (My places were updated immediately after adding in these scripts.) I can't click on a shirt to bring up a prompt, or open up the cart? I am sure that the lack of local scripts may have something to do with the problem, however I do not understand how the script could work in studio and not in game? Even a simple script that opens and shuts the cart doesn't work? What do I do?

none of these are local scripts, however besides the card duplication messup, they all work great in studio, so...?

and if you were wondering why i made something initially simple complicated, yes i want it to be this complicated because i want to make something original. I know there are easier clothes buying scripts i can make but i wanna make this one more ambitious.

  • script for the prompt that shows up when a player clicks on a shirt
script.Parent.ClickDetector.MouseClick:connect(function()
    local player = game.Players.LocalPlayer
    local cart = player.PlayerGui.Cart.CartOverlay.CartBox.ItemSelection
    player.PlayerGui.AddToCartPrompt.Prompt.Visible = true


    function FindShirtID()
        if true then

            return
                (string.sub(script.Parent.Parent.Body.Shirt.ShirtTemplate, 14))
            end
        end 

    player.PlayerGui.AddToCartPrompt.Prompt.YesButton.MouseButton1Click:connect(function()
        print("Yes Button Clicked")
        player.PlayerGui.AddToCartPrompt.Prompt.Visible = false
        game.ServerStorage.ItemBox:Clone().Parent = cart
        cart.ItemBox.ItemID.Value = FindShirtID()
        cart.ItemBox.Name = cart.ItemBox.ClothesName.Text
        cart.Parent.Visible = true
        print("Card Successfully Duplicated: Shirt 1") -- there are different types of these scripts, with Shirt 1, Shirt 2, and Shirt 3

    end)

    player.PlayerGui.AddToCartPrompt.Prompt.NoButton.MouseButton1Click:connect(function()
        player.PlayerGui.AddToCartPrompt.Prompt.Visible = false
    end)

end)

  • script for opening and closing the virtual cart manually
script.Parent.MouseButton1Click:connect(function()
    local openevent = script.Parent.Parent.Parent.Parent.Cart.CartOverlay.CartBox

    if openevent.Visible == true then
            openevent.Visible = false
        elseif openevent.Visible == false then
            openevent.Visible = true
    end
end)
  • script for getting the shirtID, getting the shirt information, and placing it into the 'cards'
function GetItemInfo()
    wait(.1)
    local Asset = game:GetService("MarketplaceService"):GetProductInfo(script.Parent.ItemID.Value)
    local item = script.Parent
    item.ClothesName.Text = Asset.Name
    item.Price.Text = "Price: "..tostring(Asset.PriceInRobux).."R$"
    item.ClothesImage.Image = Asset.IconImageAssetId
    item.MadeBy.Text = Asset.Creator.Name
    print("Gathered Item Info for Card: "..Asset.Name)

end

GetItemInfo()

What shows up on Output after clicking 'Yes' on 3 different shirts-

  • Click 1: (how it should be all the time)

Yes Button Clicked

Card Successfully Duplicated: Shirt 1

Gathered Item Info for Card: ReXx Camo Sweatshirt

  • Click 2: Yes Button Clicked

Card Successfully Duplicated: Shirt 2

Yes Button Clicked

Card Successfully Duplicated: Shirt 1

Gathered Item Info for Card: ReXx Camo Sweatshirt

Gathered Item Info for Card: ReXx Red Plaid Sweatshirt

  • Click 3: Yes Button Clicked

Card Successfully Duplicated: Shirt 3

Yes Button Clicked

Card Successfully Duplicated: Shirt 2

Yes Button Clicked

Card Successfully Duplicated: Shirt 1

Gathered Item Info for Card: ReXx Red Plaid Sweatshirt

Gathered Item Info for Card: ReXx Camo Sweatshirt

Gathered Item Info for Card: Black Smoke Sweatshirt

0
Here is a quick little answer to get you going in the right direction. Problem one: since your essentially making a catalog you might want to store the user id values in an array to keep track of everything better: http://wiki.roblox.com/index.php?title=Table#Arrays . TheGreatSailor 20 — 6y
0
Problem Two: Roblox Studio play isn't the same as when you play your game in the real website, for future purposes when testing your game use the start button instead of the play. Furthermore assuming you have filtering enabled on you have to use remote events and remote functions to communicate between server and client. If you have any more questions message me TheGreatSailor 20 — 6y
0
Okay I’m getting a little more understanding on the issue. Problem 1 is a little tough, since I am still confused on the duplication issue, but focusing on using remote events and functions should fix problem two. I am a little confused on why I should keep track of user ids. My script indexes to local player and operates within it, is there a need for tracking user ids? BronzedMocha 60 — 6y

Answer this question