Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Not Removing From Table Correctly?

Asked by
Donut792 216 Moderation Voter
4 years ago

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
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 {}? killerbrenden 1537 — 4y
0
setting back to {} didn't work and let me try that for loop real quick Donut792 216 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

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!

0
so new issue found if i try printing the values before and after it says 0 Donut792 216 — 4y
0
So, the values are not being added to the table? I'm assuming as it says 0 before? killerbrenden 1537 — 4y
0
yeah they print off as 0 even though i have table.insert before it Donut792 216 — 4y
0
Did you check if the voting values are changing? killerbrenden 1537 — 4y
View all comments (7 more)
0
yeah that part works fine Donut792 216 — 4y
0
Hmm. Not sure then, it might have to do something with the inserting values part. killerbrenden 1537 — 4y
0
well thanks for helping im going to upvote your answer since it was correct just a new issue arised Donut792 216 — 4y
0
Alright, thanks! Hope this gets fixed! killerbrenden 1537 — 4y
0
well apparently there is no inserting issue now and i didn't even mess with anything with the inserting Donut792 216 — 4y
0
talk to me on discord? now its deleting correctly but the selection box is staying on the first one selected Donut792#1329 Donut792 216 — 4y
0
I sent you a request killerbrenden 1537 — 4y
Ad

Answer this question