I am trying to create a shopping game on roblox, with a virtual cart which players can put their selected items into. The script below is meant to stop duplicated items from reaching the cart. What's supposed to happen is that before the item gets transferred into the cart, the script checks the item's ID and then checks the ID of each item inside the cart to see if they match. If they do, then the script will return boolean foundDuplicate as true(thanks climethestair), and that will cause a prompt to show up. For some reason the script, even though line 5 should stop duplicates, still goes on and returns foundDuplicate as false, which causes the item to be duplicated. I already checked if the script is indexing to a value at the right place at line 5, so I know that it should be working. I'm stumped, help?
Note: #Cart:GetChildren() does work. Because GetChildren() returns a table of an object's children, Cart:GetChildren does get identified as a table and # recognizes it as a table. Please focus less on that.
script.Parent.MouseButton1Click:connect(function()
local CartBox = script.Parent.Parent.Parent.Parent.Parent.Cart.CartGUI
local Cart = CartBox.CartBody.ItemSelection
local ID = script.Parent.Parent.Parent.ID.Value
local Itembox = script.Parent.Parent.Parent.Parent.BoxHold.ItemBox
local prompt = game.Players.LocalPlayer.PlayerGui.DuplicateItemPrompt
local card = script.Parent.Parent.Parent
local foundDuplicate = 1
if #Cart:GetChildren() > 2 then -- if there is at least 1 item in the cart
for i,item in pairs(Cart:GetChildren()) do -- for every item in the cart, cycles through every item
if item:IsA("Frame") and item.Name == "ItemBox" then -- checks if the selected item is an item
if item.ImageLabel.ID.Value == ID then -- checks if ID is the same
print("Filtered out Info Box... Item is Duplicated")
foundDuplicate = 2 -- returns true, goes to foundDuplicate
break
elseif item.ImageLabel.ID.Value ~= ID then
print("Filtered Info Box... Not Duplicated")
foundDuplicate = 3 -- returns false, continues cycle
end
else
print("Filtering Non Info Box...")
end
end
end
if #Cart:GetChildren() == 2 then -- if there is no items in the cart then
card.Parent.Adornee = nil
CartBox.Visible = true -- script transfers item to cart
local NewBox = Itembox:Clone()
NewBox.Parent = Cart
NewBox.Visible = true
NewBox.ImageLabel.LogoImage.Image = script.Parent.Parent.Parent.ItemImage.Image
print("ItemBox Cloned")
NewBox.ImageLabel.ID.Value = ID
print("Clothing ID transferred to new Item Box")
end
if foundDuplicate == 2 then -- checks if foundDuplicate is true or not
print("foundDuplicate is Executing Prompt")
prompt.Enabled = true
prompt.PromptBox.Active = true
foundDuplicate = 1
elseif foundDuplicate == 3 then
wait(0.5)
print("foundDuplicate is clean")
card.Parent.Adornee = nil
CartBox.Visible = true
local NewBox = Itembox:Clone()
print("Cloned Item Box")
NewBox.Parent = Cart
NewBox.Visible = true
NewBox.ImageLabel.LogoImage.Image = script.Parent.Parent.Parent.ItemImage.Image
print("ItemBox Cloned")
NewBox.ImageLabel.ID.Value = ID
print("Clothing ID transferred to new Item Box")
foundDuplicate = 1
end
end)

25 comments
why don't you use foundDuplicate as a boolean (true or false) rather than integers?
Why have you posted a duplicate question, and then tried to hide it by deleting the old one? https://i.imgur.com/IgmGfQ7.png
Old question available in cache here: https://webcache.googleusercontent.com/search?q=cache:8VRAuWETowoJ:https://scriptinghelpers.org/questions/61980/script-ignores-if-then-function-and-always-duplicates-items+&cd=1&hl=en&ct=clnk&gl=uk
Instead of deleting old questions and making new, just edit the original question. No foul play is being done here, fredfishy.
Why would you delete the old question unless you were specifically trying to cover up the fact that you knew you shouldn't be reposting the same question?
Why would he try to hide it if it's the same question?
He didn't put in his full script, so it seemed that instead of editing it, he made a new one to correct the mistake.
He had edited in the full script, the cache was slightly out of date. He received a couple of answers as well referring specifically to line 11. I obviously can't prove this because the cache is all I have.
odd, what kind of foul play do you think he would be up to then? What possibly could he gain from doing this? Just seems like he's new to the site to me.
Bumps the question up to the tippy top. From what I remember it was about to fall off the first page.
Mo benefit if he's already gotten answers. He knows not to do it now though, so best to just let it go.
Im going to start off with saying im sorry, for not knowing the rules on how to use scripting helpers fully. I thought this was simply a site to answer questions dedicated to scripting issues on roblox. I didn't know the full intricacy of this site and that is my own fault. But 2 quams i have. 1, what is the matter with people on this site? I understand I broke the rules,
I don't understand the heavy amount of policing in this site. What's the goal?
This leads to 2, what is the matter with this site in general? There's no general order to the site, why is there no categories? Why is there a group of moderators for a site so disordered? Why are the moderators so loyal to this site despite it being so disordered?
Why is there reputation? Why is there a disgust towards beginning developers from those with high reps? Why do those moderators have a mall cop complex as if they are providing justice by shutting down questions
Reposting a question is one of the only things that make sense on this site. You want answers, and since every question is funneled into 1 section and upvoting is only giving to higher reps, of COURSE an asker would duplicate their question to get back onto the top. But instead of natural human logic, you fred decide to paint a picture as if I was partaking in illegal activity.
It's not disordered, bad questions and bad users make it disordered. Besides I'm sure you would aprecieate it more if we had the least amount of control over you. The site is vastly community driven, but we still have a small and dedicated staff team. There isn't heavy policing, but staff will take necessary action if anyone is breaking the rules and not using the site as intended.
Reputation provides credibility, and perks and abilities to help keep the site in order. The primary reason you see veterans look down on newbies, is because newbies largely do not read the rules, or know how to use the site effectively or as it is intended.
nobody but those devoted to the site have understanding on the rules, because it is simply presented as a forum for roblox devs at surface. And it is disordered, because obviously it is meant for more advanced developers, not for those who are beginners. If you guys had a way to divide questions between those who are experienced and those who aren't, then this site would make sense.
The site is friendly for beginners and experienced. I don't see how you get the idea that it is merely presented as a forum. You can learn pretty much anything about the site here: https://scriptinghelpers.org/help
If you guys had a way to divide questions based on their category, it would also make sense, but you don't. You dont present your rules to anyone who is casually asking a question. Most of the active moderators are as unhelpful and judgmental as your buddy fred, and reputation goes to negative numbers. Reputation is good in concept, but answers are altered because of the level of reputation.
No, they're not. We don't have categories because your title should tell us everything about it. Reputation doesn't change your question at all. If you can ask and answer efficiently and constructively you will do just fine. I am doing my best to be as helpful as possible, and I hope you know I am not doing this to be a jerk.
I know you're not a jerk. You're one of the better people on this site. But you cannot speak for all moderators when you say reputation does change your question. And even though the titles do give a bit of insight to the question, all types of questions get funneled into one spot. When it falls off the first page it wont be answered. nobody upvotes unless the question is interesting to them.
We are continuously working to provide more incentive to up vote questions, and unfortunately nowadays, not many people up vote or answer questions. I can assure you that all of our mods have good intentions, and if you believe you've been treated unfairly, you can file a complaint at https://scriptinghelpers.org/contact but before you do so, make sure that you are familiar with the rules.
It can just be so much better with less condescending mods, questions that don't fall off after an hour without being answered, a replacement to reputation, or at least taking out neg reps, thats all.