A Roblox Community
Would you like to react to this message? Create an account in a few clicks or log in to continue.

A Roblox Community

A community of Robloxians who want to learn to script and build on Roblox Studio.
 
HomeLatest imagesRegisterLog in
If you're a experienced coder make some tutorials! It would really help the site grow.
Make sure you read the rules(Which can be found by clicking here)
If you're a beginner at coding, try some tutorials.
We have many Moderators/Admins watching this site. Contact them with Questions.
Let us know what your favorite sport is. By clicking here to vote (Click here)
This site is becoming inactive. Lets make it active.
Log in
Username:
Password:
Log in automatically: 
:: I forgot my password
Top posters
blueymaddog
Functions. Vote_lcapFunctions. Voting_barFunctions. Vote_rcap 
naknak
Functions. Vote_lcapFunctions. Voting_barFunctions. Vote_rcap 
Supernapalm
Functions. Vote_lcapFunctions. Voting_barFunctions. Vote_rcap 
m27frogy
Functions. Vote_lcapFunctions. Voting_barFunctions. Vote_rcap 
slayer9365
Functions. Vote_lcapFunctions. Voting_barFunctions. Vote_rcap 
myrco919
Functions. Vote_lcapFunctions. Voting_barFunctions. Vote_rcap 
branefreez
Functions. Vote_lcapFunctions. Voting_barFunctions. Vote_rcap 
ninga95
Functions. Vote_lcapFunctions. Voting_barFunctions. Vote_rcap 
CloneTrooper787
Functions. Vote_lcapFunctions. Voting_barFunctions. Vote_rcap 
raboy117
Functions. Vote_lcapFunctions. Voting_barFunctions. Vote_rcap 
Top posting users this month
No user
Latest topics
» Where to go from here.
Functions. EmptySeptember 14th 2020, 1:20 pm by MrNicNac

» Send me an Email
Functions. EmptySeptember 14th 2020, 1:16 pm by MrNicNac

» [v1.6.0.0] Lua Script Obfuscator [No Bytecode]
Functions. EmptyJuly 6th 2015, 7:38 pm by m27frogy

» New Site Possibly
Functions. EmptyJuly 6th 2015, 4:16 pm by m27frogy

» Ambassador!
Functions. EmptyApril 15th 2015, 11:40 pm by naknak

» Boop - Tag
Functions. EmptyApril 13th 2015, 9:46 pm by naknak

» Vip Class Script
Functions. EmptyApril 13th 2015, 4:54 pm by naknak

» Who's active?!
Functions. EmptyApril 13th 2015, 4:52 pm by naknak

» Genesis Point
Functions. EmptyJuly 17th 2014, 7:04 pm by branefreez

» Reward System
Functions. EmptyJuly 17th 2014, 5:41 am by m27frogy

» Script Request
Functions. EmptyJuly 10th 2014, 11:43 am by naknak

» local scripts?
Functions. EmptyJuly 10th 2014, 11:39 am by naknak

» Project: Reconstruction [Died]
Functions. EmptyJuly 10th 2014, 11:36 am by naknak

» Hi. I am new here
Functions. EmptyApril 26th 2014, 4:01 pm by altshiftkey

» What's your favorite sport?
Functions. EmptyJanuary 1st 2014, 2:13 pm by m27frogy

» FlashLight Script
Functions. EmptyJanuary 1st 2014, 2:11 pm by m27frogy

» Gun Making! [READ DESC]
Functions. EmptyJanuary 1st 2014, 2:10 pm by m27frogy

» Hi, I am new here!
Functions. EmptyNovember 26th 2013, 3:33 pm by Keanu73

» Improve Coding
Functions. EmptyOctober 26th 2013, 1:12 pm by pook03

» Simple Button
Functions. EmptySeptember 1st 2013, 6:19 pm by branefreez


 

 Functions.

Go down 
4 posters
AuthorMessage
myrco919
Intermediate Scripter
Intermediate Scripter
myrco919


Posts : 190
Join date : 2011-01-21
Age : 26
Location : Holland

Functions. Empty
PostSubject: Functions.   Functions. EmptyJanuary 21st 2011, 4:48 pm

Welcome to my first tutorial post on this site

Okay let's start with some easy things;
_________________________________________________________________________
function hit(part)
print(part.className)
end
script.Parent.Touched:connect(hit)

Explaintion; The first line is naming a function to ´hit´ and naming the arguments ´part´ (in this touched Script the arguments will be the part that touched it).
The second line will print the part´s className (The part whoever touched it. to see what it print try this; View>Output)
The tirth line will end the function. Note; end´s are needed for an if statement, a function and do (such as for......do and while .... do)
The fourth line is epicley a must in this touched Script; when the script´s parent is hitted|touched then it will run the function name in the connect arguments so we named a function earlier to ´hit´ and when script.Parent is hitted|touched then it will run that function.
_________________________________________________________________________

Anoymous functions.
The Anoymous functions are pretty much the same ash normal functions, but there are changes;

script.Parent.Touched:connect(function(p)
print(p.className)
end)

This will work pretty much ash the normal functions, expect they don´t have a name, the connection is in the begin and the function end needs an ´)´. (only the function!)

_________________________________________________________________________

Calling functions

Calling functions is simple, for example;

function classname(p)
print(p.className)
end

classname(Workspace.myrco919.Head)

Now we name a function ´classname´ and the argument ´a´.
The second line it will print a´s className
The tirth line will end the function.
The fouth line; The suprising part is here, we called a function the ´classname´ (function name) my head wich will result into `Part´ since my head´s className is part.

Well this was my first guide, hope it helped.
Back to top Go down
myrco919
Intermediate Scripter
Intermediate Scripter
myrco919


Posts : 190
Join date : 2011-01-21
Age : 26
Location : Holland

Functions. Empty
PostSubject: Re: Functions.   Functions. EmptyJanuary 21st 2011, 4:49 pm

Sorry I made a small mistake;

function classname(p)
print(p.className)
end

classname(Workspace.myrco919.Head)

Back to top Go down
naknak
Administrator
Administrator
naknak


Posts : 878
Join date : 2010-07-30

Functions. Empty
PostSubject: Re: Functions.   Functions. EmptyJanuary 21st 2011, 6:30 pm

Fixed it for you ;)
Back to top Go down
myrco919
Intermediate Scripter
Intermediate Scripter
myrco919


Posts : 190
Join date : 2011-01-21
Age : 26
Location : Holland

Functions. Empty
PostSubject: Re: Functions.   Functions. EmptyJanuary 22nd 2011, 5:00 am

Tough it's very usefull calling a function, mostly it decreases the amount of time that is needed;

local door = script.Parent

function open()
door.Transparency = 0.5
door.CanCollide = false
wait(2)
for i=0.5, 0, 0.1 do
door.Transparency = i
wait(0.3)
end
end

door.Touched:connect(function(p)
local h = p.Parent:findFirstChild("Humanoid")
if h~=nil then
if p.Parent.Name == "myrco919" then
open()
elseif p.Parent.Name == "naknak" then
open()
end
end
end)
Back to top Go down
slayer9365
Expert Scripter
Expert Scripter
slayer9365


Posts : 233
Join date : 2010-07-31
Age : 29

Functions. Empty
PostSubject: Re: Functions.   Functions. EmptyJanuary 22nd 2011, 4:39 pm

I like to only make multiple functions when I need to do the same thing more than once.
Back to top Go down
myrco919
Intermediate Scripter
Intermediate Scripter
myrco919


Posts : 190
Join date : 2011-01-21
Age : 26
Location : Holland

Functions. Empty
PostSubject: Re: Functions.   Functions. EmptyJanuary 25th 2011, 10:02 am

Altough I have another example;

local names = {"J0HN"}

function check(ietm)
for _,v in pairs(names) do
if ietm.Name == v then
return true
else
return false
end
end
end

game.DescendantAdded:connect(function(p)
if check(p) then
p:remove()
print(p.Name.." Was a fire virus.")
else
print(p.Name.." Wasn't a fire virus")
end
end)
Back to top Go down
naknak
Administrator
Administrator
naknak


Posts : 878
Join date : 2010-07-30

Functions. Empty
PostSubject: Re: Functions.   Functions. EmptyJanuary 25th 2011, 6:39 pm

You could just make that into one function.
Back to top Go down
blueymaddog
Administrator
Administrator
blueymaddog


Posts : 1081
Join date : 2010-12-09
Age : 26

Functions. Empty
PostSubject: Re: Functions.   Functions. EmptyJanuary 26th 2011, 10:09 am

local names = {"J0HN"}
game.DescendantAdded:connect(function(p)
for _,vir in ipairs(names) do
if (p.Name == vir) then
p:remove()
print(p.Name.." Was a fire virus.")
else
print(p.Name.." Wasn't a fire virus")
end
end
end)
Back to top Go down
Sponsored content





Functions. Empty
PostSubject: Re: Functions.   Functions. Empty

Back to top Go down
 
Functions.
Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
A Roblox Community :: Tutorials and Resources :: Beginner-
Jump to: