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

How to constantly update a table? (Short code)

Hey guys,

I'm trying to keep my t table constantly updated with the names of local slots (the names of slots are numbers from 1-4). I'm trying to constantly update the table only with names of slots inside which the User.Value == false otherwise don't include the name in the table if the User.Value == true. I hope you understand what I am trying to achieve, if not - Please feel free to ask me any question in the comments below this post.

My hierarchy: http://i.imgur.com/qExP1D1.png

My code:

while true do wait()
local t = {1, 2, 3, 4}
local slots = script.Parent.Parent.Slots:GetChildren()
local emptyslot = script.Parent.Value
	for i,v in pairs(slots) do
		if v.Used.Value == false then
			table.insert(t,tonumber(v.Name))
			number = (math.min(unpack(t)))
			emptyslot = number
		end
	end
end

1 answer

So there are some "slots" and you want to get the lowest one that is unused?

local t = {} --start empty
local slots = script.Parent.Parent.Slots:GetChildren()
local emptyslot = script.Parent
for _,slot in pairs(slots) do
    if not slot.Used.Value then
        table.insert(t,tonumber(slot.Name))
    end
end
number = math.min(unpack(t))
emptyslot.Value = number --I think you want to set this value, not a variable

I recommend you put this in a function and calculate when you need it, or when things change, not constantly.

4 comments

0

I'm trying to: get all of slots and take their name, then put them in a table but only if the value slots.Used.Value == false, otherwise ignore it. This isn't working that way

0

That's exactly what it does. Maybe reconsider what you want then ask a better question

0

A bit of a weird situation, because the script doesn't error, but also doesn't function (?)

0

It is raw code. Either loop it or read what I said (put it in a bigger script).

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