Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Not Removing From Table Correctly?

ok so my issue is im finding the highest number in my table and that is working fine but once the script iterates again the old values are still there obviously, so i have to delete them but for some reason i cant figure out how and i have tried 2 methods the first was using table.remove and the second was deleting key by key

Script:

local Screens = script.Parent.MapVotingScreens:GetChildren()
local AlsoScreens = script.Parent.MapVotingScreens:GetDescendants()
local highest = 0
local nums = {}

while wait(.5) do
	for x,y in pairs(Screens) do
		local Votes = y.Votes
		table.insert(nums,Votes.Value)
		for i,v in pairs(nums)do
		    if v > highest then
		        highest = v
				for k,d in pairs(AlsoScreens) do
					if d:IsA("SelectionBox") then
						d.Visible = false
					end
				end
				y.SelectionBox.Visible = true
		    end
		end
		nums[x] = nil --table.remove(nums,x)
	end
end

2 comments

0

Try using a for loop for every value inside of the nums table and remove each one like that? Or couldn't you just set nums back to {}?

0

setting back to {} didn't work and let me try that for loop real quick

1 answer

✓ Accepted answer

There's 1 way I thought of doing this as well.

  1. Find the position of each value in the table and remove it.

Method 1

local nums = {}

for _,val in pairs(nums) do
	local posVal = table.find(nums,val)
	wait(0.1)
	table.remove(nums,val)
end

This will iterate through the table and find the position of each value in the table and remove it.


I'm pretty sure both of these works. But, if this helped don't forget to select this as the answer!

11 comments

0

so new issue found if i try printing the values before and after it says 0

0

So, the values are not being added to the table? I'm assuming as it says 0 before?

0

yeah they print off as 0 even though i have table.insert before it

0

Did you check if the voting values are changing?

0

yeah that part works fine

0

Hmm. Not sure then, it might have to do something with the inserting values part.

0

well thanks for helping im going to upvote your answer since it was correct just a new issue arised

0

Alright, thanks! Hope this gets fixed!

0

well apparently there is no inserting issue now and i didn't even mess with anything with the inserting

0

talk to me on discord? now its deleting correctly but the selection box is staying on the first one selected Donut792#1329

0

I sent you a request

This discussion is preserved as it was. New answers, comments, and votes are closed.