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

Basic Scripting help colons,periods,parenthesis, etc?

I'm starting to learn how to script from a book on ROBLOX about it, and i'm kinda confused. What's the point of things like, colons, parenthesis, and periods in scripting and when am I supposed to use them?

2 answers

✓ Accepted answer

First off, I only know of a single book concerning Roblox Lua, and it's not very good. I highly recommend the wiki.

Periods are used to search for a child or property by name.

--Get workspace
workspace

--Get a Part in workspace
workspace.Part

--Get the Part's transparency
workspace.Part.Transparency

Notice how we always go from broad to specific.

Parentheses are used for functions, calling functions, and for order of operations. When concerning functions, they contain parameters and arguments (if any exist).

function add(a, b)--Create a function
	print(a + b)
end
add(1, 5) --Call the function

If you've payed attention in math class, then you know about order of operations.

print(2 + 2 * 5) --> 12
print( (2 + 2) * 5 ) --> 20

Colons are used for methods. Methods are special functions that you use on an object.

--Here, Destroy() is the method that we're calling on Part. Notice how the colon is used.
workspace.Part:Destroy()

1 comment

0

Whelp u did a way better job explaining lol.

Hi. Well first off you were wondering how periods worked. You can use periods in a lot of ways like calling variables and using connections one way you could use stings is

part = script.Parent -- that calls a variable out and when u have a script in a part it's simply making it where we can use the part in the script.

Parenthesis is what you could use to make a function

Function ontouched() -- this made a function called on touched so what ever happens in the script happens between the parenthesis. 
Function ontouched(hit) --this is making the function hit for sure and fire so this function makes the script run

Let me know If this helped and Srry if it was confusing because I'm on mobile. :)

1 comment

0

Who down voted:c

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