Lesson 2. "Watch Out With Warn()"

Welcome Back To Lunar Script School!

Lesson 2: "Watch Out with warn()"
Last Week, We Talked About Print() Now, In this lesson, we'll dive into another useful tool in Roblox Lua: the warn() function.

The warn() function is like a caution sign in your code. It's great for alerting you about potential issues or things you should keep an eye on.

Let's explore how it works:

1. Using warn() to Alert:

   warn("Hey there! Watch out for that!")

   Just like print(), this line will show a message, but with a special warning icon in the output window. It's perfect for drawing attention to important information.

2. Warning with Variables:

   local dangerLevel = 5
   warn("Danger level is:", dangerLevel)

   Here, we're warning about a variable called `dangerLevel`. It's a great way to keep track of important values during testing or debugging.

3. Highlighting Potential Problems:
   local playerHealth = -10
   if playerHealth < 0 then
       warn("Player health is negative!")
   end

   In this example, we're using warn() to signal a potential problem. If the player's health goes below zero, the warning message will pop up, letting us know something might be wrong.

With the warn() function, you can add an extra layer of awareness to your Roblox Lua scripts. Keep an eye out for potential issues, and happy scripting!

Comments

Popular posts from this blog

Lesson 1. "Hello World!"

Lesson 5: "Interactive Scripting - Click Detectors, Proximity Prompts, and More"

Lesson 6: "Client And Server Scripts"