The error says I'm Concatenating

  1. What do you want to achieve?
    I want to make the coding to show that if a previous door exists, then the next “future” door will have the same position, but far.
  2. What is the issue?
    It says an error even though the pre-existing door exists.

1 Like

line 17 should say

local DoorFound = game.Workspace.Doors:FindFirstChild("Door"..tostring(script.NumberVal.Value-1))
1 Like

yeah line 17 is the problem, let me see if that works.

1 Like

It works! Wait, why do you use tostring? and also is there any variants of it?

2 Likes

It probably works without the tostring to be honest, you might want to try it out.

I used it because:

  • “Door” is a string (obviously)
  • numberVal.Value - 1 will be a number (I don’t think lua has integer as a data type[?])

So essentially, you’re concatenating a string with a number.

Now some languages will throw an error if you try to do that, and will require you to convert the integer into a string - but I don’t think lua actually cares and will just do it automatically.

and also is there any variants of it?

What do you mean?

1 Like

im guessing he might be referring something like tonumber(), which is a variant of tostring()

3 Likes

Like variants as I mean like similiar functions to “tostring” like is there functions similiar to it that converts something into a string?

2 Likes

I dont think so. After all, the to string function converts any input to a string - so I don’t see a need for a variant?

For example:

local brickcolor = BrickColor.new("Really red")

print(typeof(brickcolor))

brickcolor = tostring(brickcolor)

print(typeof(brickcolor))

the output is:

  • BrickColor (for the first print)
  • string (for the second print)

Like @iamdevegg said, there is tonumber() which can be used to convert something into a number, for example:

local variable = "5"
print(tonumber(variable) + 3)

Prints 8.

Interestingly though, it still prints 8 even without the “tonumber” being added - I think this has something to do with the way lua handles data types, but I’m by no means some lua expert.

EDIT: heres a pretty useful read:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.