I am confused about the spawn function.
spawn(function()
end)
Can someone please explain what it is/does? Thanks!
I am confused about the spawn function.
spawn(function()
end)
Can someone please explain what it is/does? Thanks!
There are two kinds of functions.
events in the game (not to be mixed up with connection lines --> http://wiki.roblox.com/index.php?title=Scripting_Book/Chapter_2#Calling_a_function).Example:
Part = game.Workspace.Part
Part:Destroy() --this deletes the part from the workspace (aka setts everything to nil)
function, then the name you want to name that function (e.x. testing), and finally the function variable (optional ; more on these here ---> http://wiki.roblox.com/index.php?title=Function#Using_Arguments_and_Parameters)Example:
function testing()
The cool things about this is that you can call the function (run the function ; activate it) any time and anywhere in the script, and when it's called it also calls runs all the lines of code inside of that function. The process of calling a function, is called a connection line. There are two ways a connection can be activated, one by typing first typing the the function name, then putting to enclosing parentheses next to it (e.x. `testing()` ).
The second way of calling a function is to add in events. Events are certain actions that happen to an object (e.x. a part gets Touched by another part). So there are three things we must include in the connection line for it to work. One, the object that you want analize, two the event of that object that your watching for, and three the function that you are calling.
Example:
function testing() --this is the function
--Do stuff
end --you must add an end to close off that function
game.Workspace.Part.Touched:connect(testing) --the Part is the object, .Touched is the event, and testing is the function were calling
This discussion is preserved as it was. New answers, comments, and votes are closed.
2 comments
BTW the first "example" I gave is not supposed to include the next paragraph in code block form. In fact, it doesn't even appear in code block form on the editor. If encounter the same issue, please contact an admin so they can fix the bug.
Question, what you said, what does it have to do with the Spawn function?