local Holders = script.Parent.Holders local Counter = 0 for _,v in pairs(Holders:GetChildren()) do if v:IsA('Folder') then v.ClickPart.ClickDetector.MouseClick:connect(function() if Counter == 1 then if v.ItemHolding.Value then if not v.Selected.Value then v.Selected.Value = true for _,selected in pairs(Holders:GetChildren()) do if selected:IsA('Folder') then if selected.Selected.Value then if selected.ItemHolding.Value.Name ~= selected.ItemHolding.Value.Name then selected.Selected.Value = false else selected.ItemHolding.Value:Destroy() selected.Holding.Value = false selected.Selected.Value = false selected.ItemHolding.Value = nil end end end end Counter = 0 end end else if v.ItemHolding.Value ~= nil then if not v.Selected.Value then v.Selected.Value = true Counter = Counter + 1 end end end end) end end
so at the line of if selected.ItemHolding.Value.Name ~= selected.ItemHolding.Value.Name then
it doesn't do anything at all, I'm trying to do like(Let's say that if red and blue then don't merge together, else merge together if they are red and red)
I'm not sure how to fix it, could someone please help me. I've been struggling for the past 1 hour and 20 minutes and it's making my annoyed
OP and I talked this over on discord and solved it there.
He had a bunch of models (holders) with blue and yellow items
inside each model.
What OP wanted to do was to be able to compare two holders
and see if each holder was holding the same item.
image for reference : https://gyazo.com/bf677f44299769fcf39c7a37e4194de9
OP kept track of what item was in each holder with an object value called ItemHolding
.
The layout of each purple holder
looked like this: https://gyazo.com/7906c28cefdb4faf752546abd213625e
We ended up using a variable to keep track if the player clicks two holders
and compared their values.
local Holders = script.Parent.Holders local firstHolder = nil --holder that was previously clicked --this function gets called when you click a ClickPart in one of the holder folders function onClick(currentHolder) --if this is our first holder that we're clicking, store that holder in `firstHolder` if(not firstHolder)then firstHolder = currentHolder --holder is not nil meaning we clicked the second item else --check if the holders both are holding items and the holders are holding the same item if((firstHolder.ItemHolding.Value and currentHolder.ItemHolding.Value) and firstHolder.ItemHolding.Value.Name == currentHolder.ItemHolding.Value.Name and firstHolder.ItemHolding.Value ~= currentHolder.ItemHolding.Value)then print("they are the same!") --remove items from holders currentHolder.ItemHolding.Value:Destroy() currentHolder.Holding.Value = false currentHolder.Selected.Value = false currentHolder.ItemHolding.Value = nil firstHolder.ItemHolding.Value:Destroy() firstHolder.Holding.Value = false firstHolder.Selected.Value = false firstHolder.ItemHolding.Value = nil else print("they are not the same...") firstHolder.Selected.Value = false currentHolder.Selected.Value = false end --reset firstHolder's value since we just clicked the second holder firstHolder = nil end end --creates click events for each ClickPart in the holder folders for _, child in pairs(Holders:GetChildren()) do if child:IsA("Folder") then child.ClickPart.ClickDetector.MouseClick:connect(function() onClick(child) end) end end