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

How do I find the first empty value?

If I have StringValues that are each named a number, 1,2,3,4,5 (and so on) How can I create a script using :GetChildren() which gets the first StringValue that has no .Value and adds a value to it?

Like if "1" has a value, but "2" doesn't, "2" would get the value "Ketchup" (All the numbers after 2 would still have no .Value)

1 answer

✓ Accepted answer

This can be done using a General For Loop to iterate through all of the Children of an object and compare their values to an empty string, then breaking the loop. Here's some code to do that.

function writeToFirstEmptyStringValue(obj, newValue)
	for _, v in ipairs(obj:GetChildren) do
		if v.IsA("StringValue") then
			if v.Value == "" then
				v.Value = newValue
				break
			end 
		end
	end
end

writeToFirstEmptyStringValue(workspace.StringValues, "Ketchup")

If my answer solved your problem please don't forget to accept it. Thanks!

1 comment

0

not general, generic. your code also errors and function name is disgusting. thank you.

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