How do i include a number in a string?

local LVRMotor = script.Parent.Parent.Parent.Indoor
local IndoorID = script.Parent.Parent.IndoorCtrlID
local INDMotor = script.Parent.Parent.Parent.Indoor.MotorIND.HingeConstraint
local OUTMotor = script.Parent.Parent.Parent.Outdoor.MotorOUT.HingeConstraint
local Beep = script.Parent.Parent.Parent.Indoor.Fan.chime
local Wind = script.Parent.Parent.Parent.Indoor.Fan.Sound
local Cmprs = script.Parent.Parent.Parent.Outdoor.Fan.OUTDOOR
local CmprsS = script.Parent.Parent.Parent.Outdoor.Fan.Startup
local OpLamp = script.Parent.Parent.Parent.Indoor.Operation
local ClickD = script.Parent.ClickDetector

hereā€™s my code, so how do I make it include the ā€˜IndoorIDā€™ number in ā€˜local LVRMotor = script.Parent.Parent.Parent.Indoorā€™ ?

Iā€™m doing this for a VRF or VRV air conditioner system and i donā€™t want to change all the settings manually one by one which can be time consuming

3 Likes

Do you want to achieve a thing like ā€œstring_numberā€?

3 Likes
local IndoorID = script.Parent.Parent.IndoorCtrlID

-- if script.Parent.Parent.Parent.Indoor is a string...
local LVRMotor = script.Parent.Parent.Parent.Indoor .. tostring(IndoorID)

-- if script.Parent.Parent.Parent.Indoor is _not_ a string
local LVRMotor = tostring(script.Parent.Parent.Parent.Indoor) .. tostring(IndoorID)
1 Like

yes I do want to achieve that.

3 Likes

so for example, if I want to reference Indoor1 with a remote control using the numbervalue, and do something with it

2 Likes

So you want to have numbers on your variables?

2 Likes

you can name your variables with numbers, for an example: local variable1 = "foo"

2 Likes

Iā€™m not sure what you want to achieve exactly lol

local Item = script.Parent["Indoor1"]
2 Likes

Yes i do want to include a number in a string as well

1 Like

I am using a NumberValue not a number in a script

1 Like

Are you referring to concatenating, per chance?

1 Like

You can do that.

local str = "hello_123" --put your string here
local strSplit = string.split(str, "_")
local numbers = ""
local characters = ""

for _, char in pairs(strSplit) do
	if tonumber(char) then
		numbers = numbers..char
	else
		characters = numbers..char
	end
end

itā€™s not working instead itā€™s saying ā€œerror-typeā€ and it doesnā€™t show the numbervalue on the input

To include a number in a string:

local numberID = 3

workspace.Model["DoorPart"..tostring(numberID)]
print(workspace.Model["DoorPart"..tostring(numberID)])

So for your task since you use a NumberValue it would maybe look like this:

local LVRMotor = script.Parent.Parent.Parent.Indoor
local IndoorID = script.Parent.Parent.IndoorCtrlID

LVRMotor.Parent["LVRMotor"..tostring(IndoorID.Value)]

NOTE: I know this reply is 8 months late, but the post is not marked as solved yet and I happened to run by.

1 Like