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 Concatenate a Specific Part of a Table using a Variable for #?

Example:

Array={"Hi","Bye","Hello","Thankyou"}
Array2={"Super","Fast","Slow","Thinker"}
StringValue="One of the Array Values"

for s=1,4 do
wait(1)
RandomArray=math.random(1,2)
if RandomArray==2 then RandomArray=Array2
else if RandomArray==1 then RandomArray=Array
StringValue=tostring(RandomArray[s]..s,' ')
s=s+1
print(StringValue)
end end end

So basically what this psuedo (it doesn't work) script is suppose to do is randomly choose an array and chronologically print the values of the array values so if RandomArray=1 RandomArray=Array and if [s] = 4 then It should print the value Thankyou. The StringValue would look like this v StringValue=tostring(Array[4]..s' ') print(Array[4]..s)==print(StringValue)

Thankyou4

Novice Scripter "SamDomino"

1 comment

0

thanks.

1 answer

✓ Accepted answer

You only need two ends and s increases by 1 by default. Also the values in the tables are already strings so there is no need for tostring() I took out the ..s,' ' because if s was 1 it would have printed "HiHi ". Finally I am pretty sure you can't put commas in the variable to concatenate that. So it would be:

Array={"Hi","Bye","Hello","Thankyou"}
Array2={"Super","Fast","Slow","Thinker"}
StringValue="One of the Array Values"

for s=1,4 do
	wait(1)
	RandomArray=math.random(1,2)
	if RandomArray==2 then
		RandomArray=Array2
	else if RandomArray==1 then
		RandomArray=Array
		StringValue=RandomArray[s] --If s was 1 then this would print: "Hi"
		print(StringValue)
	end
end


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