Log in to vote

How can I project a variable on a GUI?

Asked by 7 years ago

In my game, I have a building with a surface GUI on a brick showing the name of the building, but I would like to know how I can have a variable on the GUI.

My game example: "Cylocx's building" on a surface GUI. but when another player has their building: "Guest 1156's building"

Thank you in advance!

1 answer

Log in to vote
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
7 years ago

You use concatenation.

I'm not sure what you have set up, so I'll assume you already have a way to get the player's name.

playername = "Bob"

GUI.Text = playername.."'s building" --Replace GUI with the correct hierarchy. 

What this does is basically combine the two strings. It does not have to be two strings though. You can use numbers as well.

local number = 10

print("I have "..number.." cookies")--It combines everything exactly, so make sure you have the spaces right!

--output: I have 10 cookies

Hope i helped!

Hmm.. it didn't work.. I put the script into the part that has the SurfaceGUI. I did Parent.SurfaceGui.Textbox.Text = playername.."'s building" DrCylonide 158 — 7y
As I said, I am assuming you have a way to get the player's name. Perci1 4988 — 7y

Answer this question