Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to put variable in text?

Hi, i'm trying to write a script that makes a TextBox's text say a message followed by a variable.

I've tried loads of different ways to write what seems like the same thing.

local p = script.Parent.Parent.CarName

while true do
	wait()
	script.Parent.Text = (("Welcome into this ")..(p))
end

also tried:

local p = script.Parent.Parent.CarName

while true do
	wait()
	script.Parent.Text = "Welcome into this "..p
end

and:

local p = script.Parent.Parent.CarName

while true do
	wait()
	script.Parent.Text = ("Welcome into this "..p)
end

Should be easy.... any help?

2 comments

0

is there any outputs for any of them? And also, What is "CarName"? Is it literally something to get the name of a model, Or is it a TextBox of some sort?

0

"CarName" is a variable.

1 answer

✓ Accepted answer

I believe your variable is incorrect. I do not know if CarName is something inside of your game, but assume you meant CarName , then you need to direct the script to the name of this so it may add it to your script.

local p = script.Parent.Parent.CarName.Name

while true do
    wait()
    script.Parent.Text = "Welcome into this "..p
end

If you actually mean Car and Name should have had a period in front, then:

local p = script.Parent.Parent.Car.Name

while true do
    wait()
    script.Parent.Text = "Welcome into this "..p
end

Future reference: You don't need a parenthesis around your string. just doing script.Parent.Text = "Welcome into this "..p will work. I believe parenthesis work as well, although I do not use them for what you're doing.

1 comment

0

Make sure Hierarchy is correct. If this doesn't work, just comment. If this does, please +1 & Thumbs Up.

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