-
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. -
What is the issue?
It says an error even though the pre-existing door exists.
line 17 should say
local DoorFound = game.Workspace.Doors:FindFirstChild("Door"..tostring(script.NumberVal.Value-1))
yeah line 17 is the problem, let me see if that works.
It works! Wait, why do you use tostring? and also is there any variants of it?
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?
im guessing he might be referring something like tonumber(), which is a variant of tostring()
Like variants as I mean like similiar functions to “tostring” like is there functions similiar to it that converts something into a string?
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:
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.