Scripting Book/Chapter 4

From Legacy Roblox Wiki
Jump to navigationJump to search


Introduction

Hi again! Welcome to chapter 4 of my Scripting Book. This time we're going to make functions with arguments.

Like in Chapter 2 when we made functions, all the said was 'Howdy, y'all!' which was pretty useless.

This time we're going to do a function that was can call by doing this:

msg("Hello friends")

And a message appers on the screen saying Hello friends.

Function Structure

Insert a script into workspace.

Now, get the function we made last time:

function msg()
    m = Instance.new("Message", game.Workspace)
    m.Text = "Howdy, y'all!"
    wait(5)
    m:Destroy()
end
  • In the brakets after 'msg' add 'text'
function msg(text)
  • Remove the text 'Howdy, y'all!' and replace it with 'text'.
    m.Text = text


And we're done! How easy was that!??

Now, to call the function all we need to add to the script is:

msg("Hello everybody!!")

And then a message appears on the script saying 'Hello everybody!!' and disapears after a five second duration.

Finished script:

function msg(text)
    m = Instance.new("Message", game.Workspace)
    m.Text = text
    wait(5)
    m:Destroy()
end

msg("Ohaidare!!")

Go to previous chapter or Continue to Chapter 5