How to Add a Display Name on Roblox

Download Article

Download Article

Roblox is an online gaming platform that allows user to create, share, and play games online with other Roblox players. Building things in Roblox Studio is a lot of fun. However, if you want to make a game, you need to learn how to script. This wikiHow teaches you how to script in Roblox.

  1. 1

    Understand what a script is. Scripts are lines of code that contain instructions for a game or program to follow. In Roblox, scripts can be used to do everything from giving (or taking away) a player's health points, making objects move, or anything you can think of. Roblox uses a programming language called Lua. In Roblox, there are three types of scripts, which are as follows:[1]

    • Server Script: A server script is a script that is stored on the server. A server script creates actions in a game that can be seen by all players.
    • Local Script: A local script is a script that is specific to a single player. A local script creates actions that can be seen by one player only.
    • Module Script: A module script contains frequently used script functions that can be used by other scripts. This is a good way to organize frequently used code so that you don't have to copy and paste or reuse the same code in multiple scripts.
  2. 2

    Open Roblox Studio. Roblox Studio has an icon that resembles a blue square. Click the Roblox Studio icon on your desktop, Windows Start menu, or Applications folder on Mac.

    • If you haven't already downloaded Roblox Studio, go to https://www.roblox.com/create and click Start Creating. Then click Download Studio.

    Advertisement

  3. 3

    Click View . It's in the menu bar at the top. This displays a panel of windows you can open in Roblox Studio.

  4. 4

    Click Output . It's in the View panel at the top of the screen. This opens the Output window. The Output window allows you to view your script in action and see any error messages your script creates.

  5. 5

    Click Explorer . It's in the upper-left corner of the View menu. This opens the Explorer window. You can use the Explorer menu to browse objects in your game and add new objects.

  6. 6

    Expand "World" in the Explorer window. To expand the "World" menu click the arrow icon next to "World".

  7. 7

    Click + next to "Workspace". It's next to the "Script" icon below "World" in the Explorer menu. This displays a pop-up menu with the different scripts you can add.

  8. 8

    Click Script . It's next to an icon that resembles a blue page. This creates a new server script with a "Hello World!" print function. If you click the "Play" icon at the top fo the screen, this will test your game and you will see "Hello World!" appear in the Output menu.

    • You can also find the options to create a new local script and a new module script in the upper-right corner.
    • Try changing the text parenthesis. The "Print" command is used to display text in the Output window.
  9. 9

    Give the script a name. To give the script a name, click the name of the script below "Script" in the Explorer menu. Then type the name you want to give it.

    Advertisement

  1. 1

    Add a part to your game. To return to your game, click the first tab next to the script tab at the top of the main view. Then use the following steps to add a part:

    • Click Model.
    • Click Part.
    • Click a part to add.
  2. 2

    Note the location of the part in the Explorer window. Most likely, it will be below "Workspace". You'll need to know the location of the object in the Explorer menu to reference it in a script.

    • Make sure the object has a unique name. If you have multiple objects called "Part", that's going to make it hard to reference a specific object in a script. To change the name of an object, click it in the Explorer menu and type the name you want to give it.
  3. 3

    Return to the script and reference write the code that references the object. Click the script tab to return to the script. To reference the part in the script, start by typing "game." followed by the location of the part (Workspace) and the object name, all separated with a period. For example, if you add a part you named "Brick" to your game, you can reference it by typing the following:

    • game.Workspace.Brick.
  4. 4

    Open the Properties window. To open the Properties window, click View in the menu bar at the top and click Properties in the upper-left corner. Then click the part to see a list of possible properties.

  5. 5

    Change the properties of a part using a script. You've already created the script that references the part. To change the properties of the part using a script, add a period (.) followed by the name of the properties you want to change. Then add an equal (=) sign followed by the value of the property. The property may be a number, or a name in quotations. You'll need to create a new line of code for each property you want to change. The following are examples of a line of code that changes the properties of a part.

    • game.Workspace.Brick.Transparency = 0.5
    • game.Workspace.Brick.Material = "Glass"
  6. 6

    Create a variable that references a part. Typing out the location and name of a part every time you want to reference it can take a lot of time. One way to shorten the process is to create a variable that references the part. Then all you have to do is type the variable name every time you want to reference the part. To create a reference variable, type "local" followed by the name of the part. Then add an equals sign followed by the location and name of the part. For example:

    • local Brick = game.Workspace.Brick.
  7. 7

    Use the variable name to change the properties of the part. After you create a variable for a part, you can use that variable name to reference the object any time after the line that created the variable. The following line of code uses the variable name to change a part's property:

    • Brick.Material = "Granite"
  8. 8

    Test your game. In order to see the results of your script, click the Test menu and click the Play icon at the. You should see the part you added change properties in the game.[2]

    Advertisement

  1. 1

    Add a block to your game. This part teaches you how to make a block that kills the player when touched. Use the following steps to add a new block.

    • Click Model.
    • Click Part.
    • Click Block.
    • Name the block "Deathblock" in the Explorer window.
  2. 2

    Insert a script into the block. This adds a script as a child object to the block. You will be able to find the script under "Deathblock" in the Explorer window. Use the following steps to insert a script into the block.

    • Right-click the block.
    • Click Insert Object.
    • Click Script.
  3. 3

    Erase the "Hello World" code. It's the place holder code at the top of the script. You don't need it so go ahead and delete it.

  4. 4

    Write function onTouch(Deathblock) in the first line. This line of code defines a function that happens when the block is touched.

  5. 5

    Write local humanoid = Deathblock.Parent:FindFirstChild("Humanoid") in the next line. In Roblox, a Humanoid is any character that can walk and interact with the game. This line of code defines the "Humanoid" variable, and then checks to see if a humanoid exists.[3]

  6. 6

    Write if (humanoid ~= nil) then in the next line. In scripting, this is what is known as an "if/then" statement. It simply says that if a humanoid is present (touching the block), move on to the next function.

  7. 7

    Write humanoid.Health = 0. This line of code drops the player's health down to 0%.

  8. 8

    Write end on the next line. This ends the "If/then function.

  9. 9

    Add another end on the next line. This ends the script.

  10. 10

    Write part.Touched:Connect(onTouch)on the next line. This line of code returns the script to it's original state and allows it to run again when another player touches the block.[4] Test your game to see how it works. Your entire script should look like this:[5]

                                                function                      onTouch                      (                      Deathblock                      )                      local                      humanoid                      =                      Deathblock                      .                      Parent                      :                      FindFirstChild                      (                      "Humanoid"                      )                      if                      (                      humanoid                      ~=                      nil                      )                      then                      humanoid                      .                      Health                      =                      0                      end                      end                      script                      .                      Parent                      .                      Touched                      :                      connect                      (                      onTouch                      )                    

    Advertisement

Add New Question

  • Question

    Can I type capital letters in scripts?

    Community Answer

    Yes, but only if it is needed to make it right. Here is an example to show you: player.Name

  • Question

    How do I make a script that will make a model talk and answer questions?

    Community Answer

    Most people use the dialogue elements that can be entered by right-clicking the object in the explorer, clicking the "Insert Object" button, and finding dialogue. It doesn't require scripting.

  • Question

    How do parents and child work in scripts?

    Destinid10_2

    Destinid10_2

    Community Answer

    They are easy to understand and apply. You can use .Parent to reference to the Parent of a item. For example: local part = script.Parent. Another practical example: local workspace = Part.Parent. For referencing Childs is a little more complex, because .Child doesn't exist. So I recommend you that when you're going to reference a Child, use basic referencing code, for example, like this: local part = game.Workspace.Part.

  • Question

    Can you teach me more about Functions? I'm not good at making Functions.

    Ziqian Gao

    Ziqian Gao

    Community Answer

    Functions ensure you don't type the same code over and over again. Functions can have values in them. To make a function, put local function NameHere()--Commands here--end. For a function with values in them, do the same above but with names in the parentheses "()" separated by commas. Local is optional. Values can be used only inside the function. Values can be a string, a number, a color, etc.

  • Question

    How do you make a button or a gui?

    Ziqian Gao

    Ziqian Gao

    Community Answer

    Put ScreenGui in StarterGui and then make a TextButton or an ImageButton and put a local script under the Button you Made and Put this: from 5 dashes to 6 dashes (-) -----function onclick()--what you want it to do on left click--end function onrightclick()--what you want it to do on right-click-endscript.Parent.MouseButton1Click:Connect(onclick)script.Parent.MouseButton2Click:Connect(onrig tclick)------. This is only for GUI on the screen. For the text with two dashes at the start, replace it with what you want it to do.

Ask a Question

200 characters left

Include your email address to get a message when this question is answered.

Submit

Advertisement

About This Article

Article SummaryX

1. Open Roblox Studio.
2. Insert a new block and name it "Deathblock".
3. Right-click the deathblock and click Insert Object.
4. Insert a new script.
5. Write "function onTouch(Deathblock)" on the first line.
6. Write "local humanoid = Deathblock.Parent:FindFirstChild("Humanoid")" on the next line.
7. Write "if (humanoid ~= nil) then" on the next line.
8. Write "humanoid.Health = 0" on the next line.
9. Write "end" on the next line.
10. Write "end" again on the next line.
11. Write "script.Parent.Touched:connect(onTouch)" on the last line.

Did this summary help you?

Thanks to all authors for creating a page that has been read 30,221 times.

Did this article help you?

How to Add a Display Name on Roblox

Source: https://www.wikihow.com/Script-on-Roblox

0 Response to "How to Add a Display Name on Roblox"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel