A Roblox Community

A community of Robloxians who want to learn to script and build on Roblox Studio.
 
HomeFAQRegisterLog 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
 
naknak
 
Supernapalm
 
m27frogy
 
slayer9365
 
myrco919
 
branefreez
 
ninga95
 
CloneTrooper787
 
raboy117
 
Top posting users this month
Latest topics
» Send me an Email
January 8th 2016, 10:14 am by naknak

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

» New Site Possibly
July 6th 2015, 4:16 pm by m27frogy

» Ambassador!
April 15th 2015, 11:40 pm by naknak

» Boop - Tag
April 13th 2015, 9:46 pm by naknak

» Vip Class Script
April 13th 2015, 4:54 pm by naknak

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

» Where to go from here.
April 13th 2015, 4:51 pm by naknak

» Genesis Point
July 17th 2014, 7:04 pm by branefreez

» Reward System
July 17th 2014, 5:41 am by m27frogy

» Script Request
July 10th 2014, 11:43 am by naknak

» local scripts?
July 10th 2014, 11:39 am by naknak

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

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

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

» FlashLight Script
January 1st 2014, 2:11 pm by m27frogy

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

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

» Improve Coding
October 26th 2013, 1:12 pm by pook03

» Simple Button
September 1st 2013, 6:19 pm by branefreez


Share | 
 

 Touched event

View previous topic View next topic Go down 
Go to page : 1, 2  Next
AuthorMessage
Guest
Guest



PostSubject: Touched event   August 2nd 2010, 3:04 pm

Please move this if its in the wrong level.

Introduction/What it is
onTouch functions are activated when a person touches a brick the script is in. They are used in lava bricks, VIP doors, and more. In this tutorial you will find out how to create an onTouch function and run it when someone touches the brick.

Setting up
First, insert a Part (aka brick). If you don't know how to do this, read a different tutorial first. Now, insert a script inside the brick. Double-click your script and it should open up. You will see:
Code:
print("Hello World!")
Delete that line. You don't need it.

Making the script
First, we need to define our function.
Code:
function onTouch()
After creating our function, we need it to do something when activated. How about we use a simple action and remove our brick?
Code:
script.Parent:remove()
That refers to the parent of the script (in this case, our brick) and then removes it. Finish the function with an end .
Now we're almost done! We need our script to activate when touched, so we'll use this connection line.
Code:
script.Parent.Touched:connect(onTouch)

The final script
Our completed script looks like this...
Code:
function onTouch()
script.Parent:remove()
end

script.Parent.Touched:connect(onTouch)

Now go test your script. Does your brick disappear when you touch it?


Does this help? Is there something incorrect within it? Tell me and I'll try to fix it.


Last edited by Nominate10 on August 2nd 2010, 5:22 pm; edited 1 time in total (Reason for editing : Title changed.)
Back to top Go down
slayer9365
Expert Scripter
Expert Scripter
avatar

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

PostSubject: Re: Touched event   August 2nd 2010, 4:55 pm

I wouldn't call it onTouch functions, because you could have the function named everything. I could have function poop(iTouchedYou). Please change the *** to the .Touched event.
Back to top Go down
Guest
Guest



PostSubject: Re: Touched event   August 2nd 2010, 5:21 pm

Yes, but most beginners refer to it as an onTouch function. Good call though, I'll change that.
Back to top Go down
slayer9365
Expert Scripter
Expert Scripter
avatar

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

PostSubject: Re: Touched event   August 2nd 2010, 5:23 pm

Well beginers need to learn some how that Names of functions don't really matter.


Last edited by slayer9365 on August 2nd 2010, 5:24 pm; edited 1 time in total (Reason for editing : My keyboard cut out halfway through my sentence)
Back to top Go down
Guest
Guest



PostSubject: Re: Touched event   January 16th 2011, 10:41 pm

Well what if another brick touches it, not including a player?
Back to top Go down
naknak
Administrator
Administrator
avatar

Posts : 878
Join date : 2010-07-30

PostSubject: Re: Touched event   January 16th 2011, 10:51 pm

It will disappear
Back to top Go down
Guest
Guest



PostSubject: Re: Touched event   January 16th 2011, 11:30 pm

So I think you should recreate you script, Nominate10.
Back to top Go down
naknak
Administrator
Administrator
avatar

Posts : 878
Join date : 2010-07-30

PostSubject: Re: Touched event   January 16th 2011, 11:58 pm

His script was meant to be the most basic form of the Touched event. To make it only activate by players, this will work:
Code:
function onTouch(hit)
if hit:findFirstChild("Humanoid") then
script.Parent:Remove()
end
end

script.Parent.Touched:connect(onTouch)


Back to top Go down
blueymaddog
Administrator
Administrator
avatar

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

PostSubject: Re: Touched event   January 17th 2011, 3:56 am

naknak is right.

_________________
blueymaddog
Administrator • Moderator • Expert Scripter
PM: blueymaddog
<+1 post. ujelly?>
Back to top Go down
naknak
Administrator
Administrator
avatar

Posts : 878
Join date : 2010-07-30

PostSubject: Re: Touched event   January 17th 2011, 12:38 pm

I always am ;)
Back to top Go down
blueymaddog
Administrator
Administrator
avatar

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

PostSubject: Re: Touched event   January 18th 2011, 8:06 am

not always. these errors you made for example:
m=Instance.new("Message",Workspace).Text=""
pcall(hit.Parent.Humanoid.Health=0 end)

_________________
blueymaddog
Administrator • Moderator • Expert Scripter
PM: blueymaddog
<+1 post. ujelly?>
Back to top Go down
Guest
Guest



PostSubject: Re: Touched event   January 23rd 2011, 4:20 pm

naknak wrote:
His script was meant to be the most basic form of the Touched event. To make it only activate by players, this will work:
Code:
function onTouch(hit)
if hit:findFirstChild("Humanoid") then
script.Parent:Remove()
end
end

script.Parent.Touched:connect(onTouch)



Incorrect. The Character of players has the Humanoid stored in the model, not one of the Parts in the model.

Code:
function Potatoes(wut)
if wut.Parent:findFirstChild("Humanoid") then
script.Parent:Remove()
end
end

script.Parent.Touched:connect(Potatoes)
Back to top Go down
slayer9365
Expert Scripter
Expert Scripter
avatar

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

PostSubject: Re: Touched event   January 23rd 2011, 4:41 pm

Very nice job catching that Potato.
Back to top Go down
Guest
Guest



PostSubject: Re: Touched event   January 23rd 2011, 5:19 pm

But I'm not a potato :O
Back to top Go down
naknak
Administrator
Administrator
avatar

Posts : 878
Join date : 2010-07-30

PostSubject: Re: Touched event   January 23rd 2011, 5:57 pm

Fine. Give me a break, everyone makes mistakes. I know what I mean, even if I say it wrong... And how were those mistakes blue?
Back to top Go down
Supernapalm
Expert Scripter
Expert Scripter


Posts : 393
Join date : 2011-01-17

PostSubject: Re: Touched event   January 23rd 2011, 7:33 pm

ikr. i was just thinking about that touch script.
Back to top Go down
http://hackthissite.org
myrco919
Intermediate Scripter
Intermediate Scripter
avatar

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

PostSubject: Re: Touched event   January 24th 2011, 10:01 am

*watches the battle*
Back to top Go down
blueymaddog
Administrator
Administrator
avatar

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

PostSubject: Re: Touched event   January 26th 2011, 10:02 am

*finds another catch!!!*

@potato, what if a talking brick touched it? ever thought of that?

use this:

Code:

script.Parent.Touched:connect(function(hit) if game.Players:GetPlayerFromCharacter(hit.Parent) ~= nil then hit:Remove() end end)

_________________
blueymaddog
Administrator • Moderator • Expert Scripter
PM: blueymaddog
<+1 post. ujelly?>
Back to top Go down
slayer9365
Expert Scripter
Expert Scripter
avatar

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

PostSubject: Re: Touched event   January 26th 2011, 5:34 pm

blueymaddog wrote:
*finds another catch!!!*

@potato, what if a talking brick touched it? ever thought of that?

I am not sure what a talking brick is, I don't think that bricks are AI yet. And if you are talking about a model with a humanoid in it, I think that most people will either rename the Humanoid, or have them anchored.
Back to top Go down
blueymaddog
Administrator
Administrator
avatar

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

PostSubject: Re: Touched event   January 26th 2011, 10:22 pm

but what if it isn't anchored and humanoid isn't renamed? lol :P

_________________
blueymaddog
Administrator • Moderator • Expert Scripter
PM: blueymaddog
<+1 post. ujelly?>
Back to top Go down
naknak
Administrator
Administrator
avatar

Posts : 878
Join date : 2010-07-30

PostSubject: Re: Touched event   January 26th 2011, 10:38 pm

Then whoever made the talking brick needs help.
Back to top Go down
blueymaddog
Administrator
Administrator
avatar

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

PostSubject: Re: Touched event   January 27th 2011, 2:27 am

lol.

_________________
blueymaddog
Administrator • Moderator • Expert Scripter
PM: blueymaddog
<+1 post. ujelly?>
Back to top Go down
ninga95
Administrator
Administrator
avatar

Posts : 122
Join date : 2010-07-30
Age : 21

PostSubject: Re: Touched event   February 10th 2011, 9:30 pm

Hey if nom looks at this i think he would be like WOW i wrote this when i first started lol Hes like an expert now
Back to top Go down
myrco919
Intermediate Scripter
Intermediate Scripter
avatar

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

PostSubject: Re: Touched event   March 5th 2011, 6:38 pm

Mistakes everywhere!

Back to top Go down
naknak
Administrator
Administrator
avatar

Posts : 878
Join date : 2010-07-30

PostSubject: Re: Touched event   March 5th 2011, 8:59 pm

Yeah, this is a pretty basic guide.
Back to top Go down
Sponsored content




PostSubject: Re: Touched event   

Back to top Go down
 
Touched event
View previous topic View next topic Back to top 
Page 1 of 2Go to page : 1, 2  Next
 Similar topics
-
» The next XP event?
» how long will this xp event last?
» [CBS]-Deathmatch Event
» Guild Event Manager ..
» 3G Event quests and other New stuff and confirmations

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