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

What if a variable isn't defined?

A friend of mine made a gun script, In his line of code I noticed that one of the variables doesn't have a value assigned to it (Character)

local Player	 = Players.LocalPlayer
local Character 
local Mouse		 = Player:GetMouse()

The script works, there's no doubt about that, but why? What does the character variable equal, and if it doesn't equal anything, why put it there in the first place?

2 comments

0

you can assign a value to a variable later on

0

So why didn't that person just declare the variable later on?

1 answer

Not assigning a value to variable within a statement makes that statement a Declaration statement, instead of a Initialization statement.

Declaring a variable just means you create a new variable that may or may not be used later on, and declaring it early means you can use it anywhere in the script as needed.

3 comments

0

But to declare it you would have to use (Character =) right? So whats the point of doing it twice?

0

Honestly there's not really a point but coding languages just have it :l

0

This is more for use in functions, loops, and proving something exists.

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