How to get 4 instances in table that have the same value

Im helping a friend to make some sort of tycoon game, there’s giraffes that work just like droppers, there’s a button called “Merge” which allows you to convert 4 giraffes with the same type into 1 better type.

But i have no idea on how can i get 4 giraffes, remove the 4 ones and replace them with a better tier one.

Could you provide the source code for the giraffe tables only the part where you need to merge and the tables?

I was trying to find a way so the for _, v at the bottom is unfinished

local CurrentGiraffes = GetGiraffes() – This should return a table. –

local Table = {}

		for _, Value in pairs(CurrentGiraffes) do
			if Value.Name == "Giraffe" then
				if Value:FindFirstChild("Tier") then
					if Value.Tier.Value == 1 then
						table.insert(Table, Value)
						return
					end
				end
			end
		end
	
		for _, v in pairs(Table) do
			
		end

Wait does this not work or is it returning an error?

There’s no errors, i also removed the return and did some changes to the for_, v below and it seems to be working i guess?

also if you can send the CurrentGiraffess table I don’t know the index’s and values of the table it’ll be easier for me

There’s the code i used.

local Table = {}

		for _, Value in pairs(CurrentGiraffes) do
			if Value.Name == "Giraffe" then
				if Value:FindFirstChild("Tier") then
					if Value.Tier.Value == 1 then
						table.insert(Table, Value)
					end
				end
			end
		end
		
		local Count = 0
	
		for _, v in pairs(Table) do
			local ChosenGiraffe = v
			if Count ~= 5 then
				Count = Count + 1
				print(Count)
				v:Destroy()
			end
		end

That means its solved or what happened?

Yeah it’s solved
(thirrrrty characteers)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.