How to see which string is empty and that stuff

So what I am trying to do is I have a few string values they are named string1 and string2 and string3 . I want my script to get all the stringvalues value and see which one is empty. So like I had string3 filled up and I was going to equip a dragon to the string and I want it closer to the player. so I would get the value of string3 and fill it in string1 or string2 (and make it find which one is empty value and to fill it in. If it was both was empty it would look for string1 instead of string2) and then make string3 empty since it has been transfered.

I know this is very confusing but if anyone could help that would be nice.

1 Like

You could probably do something like this, all though I’m assuming by empty you mean just “” and not whitespace.

local string1, string2, string3 = -- Variables here
if string1 == "" then string1 == string3 end
if string2 == "" then string2 == string3 end
string3 = ""

There is obviously some ways of automating this and this itself is rather ugly, but I find it hard to understand what you exactly want to do

I want script to see what string value is empty and what there name is. Example

string3 is already filled up and string 1 and string 2 is empty so I would want it to choose string 1 instead of string2 since 1 is smaller then 2 and to fill string 1.

Well you can probably just use the method I gave before with some slight tweaks. It won’t look pretty or efficient but it works.

local string1, string2, string3 = -- Variables here

if string1 == "" and not string3 == "" then string1 = string3
elseif string2 == "" and not string3 == "" then string2 = string3 end
if string1 == "" and not string2 == "" then string1 == string2
elseif string3 == "" and not string3 == "" then string3 == string2 end
if string2 == "" and not string1 == "" then string2 == string1 
elseif string3 == "" and not string1 == "" then string3 == string1 end

very ugly code.

agree very ugly… maybe I should tell you what I am trying to do with this

I am trying to make it so that the pets are not just in the far back by filling string3 in instead of string1 so that the pet is always close to the player and not just in the far back.

You could create a table for the string values and use ipairs to loop through the string. Within the ipairs loop, you can check to see if the string values == “” (empty string)

local stringFolder = workspace.Folder
local stringValues = stringFolder:GetChildren()

for _, stringValue in ipairs(stringValues) do
	if stringValue.Value == "" then --Empty string value.
		--Do code.
	else --Not an empty string value.
		--Do other code.
	end
end

Should be as simple as this.

7 Likes