Why is the table not sorting my strings = integer and when inserting a string = integer to the table the output is 1 = false

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to know why it is not working as intended, please : D
  2. What is the issue? Include screenshots / videos if possible!
    Why is the table not sorting my strings = integer and when inserting a string = integer to the table the output is 1 = false. The output is also not in order
-- local newtable = {
	["value1"] = 10,
	["value2"] = 20,
   ["value3" ] = 5

	
	
	
	

}





print(newtable)


local newco = coroutine.create(function()
	
	while task.wait(4) do
		table.sort(newtable,function(a,b)

			return a > b 

		end)
		
		
		
		
		
		
		for i,v in pairs(newtable) do

			print(i,v)



		end
	end
	
end)


coroutine.resume(newco)



for i,v in pairs(newtable) do

	print(i,v)



end




table.insert(newtable, "value4" == 15) -- when inserted I am getting 1 false since commas

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

Dictionaries can not be sorted. Simple as that.

also, instead of

table.insert(newtable, "value4" == 15)

did you mean to do

newtable["value4"] = 15

The way you have it, it adds a boolean value

when I write newtable[“value4”] = 15 I get red lines

What text shows when you hover over the red lines?
Did you make sure to not include the table.insert bit?

yeah I removed it and now it works I just forget to remove table insert

but now it is still not sorting properly

From my first message:

Dictionaries can not be sorted. Simple as that.

oh okay thanks for telling me : )

You can convert it to an array like so:

local newtable = {
	[1] = 10,
	[2] = 20,
	[3] = 5
}

table.insert(newtable, 15)

task.defer(function()
	while task.wait(1) do
		table.sort(newtable, function(a,b)
			return a > b
		end)

		print(newtable) --> will always print in order of highest to lowest value
	end
end)

Also I switched from coroutines to task.defer because in the code sample you gave us you never pause it.

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