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
Touched event Vote_lcapTouched event Voting_barTouched event Vote_rcap 
naknak
Touched event Vote_lcapTouched event Voting_barTouched event Vote_rcap 
Supernapalm
Touched event Vote_lcapTouched event Voting_barTouched event Vote_rcap 
m27frogy
Touched event Vote_lcapTouched event Voting_barTouched event Vote_rcap 
slayer9365
Touched event Vote_lcapTouched event Voting_barTouched event Vote_rcap 
myrco919
Touched event Vote_lcapTouched event Voting_barTouched event Vote_rcap 
branefreez
Touched event Vote_lcapTouched event Voting_barTouched event Vote_rcap 
ninga95
Touched event Vote_lcapTouched event Voting_barTouched event Vote_rcap 
CloneTrooper787
Touched event Vote_lcapTouched event Voting_barTouched event Vote_rcap 
raboy117
Touched event Vote_lcapTouched event Voting_barTouched event Vote_rcap 
Top posting users this month
No user
Latest topics
» Where to go from here.
Touched event EmptySeptember 14th 2020, 1:20 pm by MrNicNac

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

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

» New Site Possibly
Touched event EmptyJuly 6th 2015, 4:16 pm by m27frogy

» Ambassador!
Touched event EmptyApril 15th 2015, 11:40 pm by naknak

» Boop - Tag
Touched event EmptyApril 13th 2015, 9:46 pm by naknak

» Vip Class Script
Touched event EmptyApril 13th 2015, 4:54 pm by naknak

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

» Genesis Point
Touched event EmptyJuly 17th 2014, 7:04 pm by branefreez

» Reward System
Touched event EmptyJuly 17th 2014, 5:41 am by m27frogy

» Script Request
Touched event EmptyJuly 10th 2014, 11:43 am by naknak

» local scripts?
Touched event EmptyJuly 10th 2014, 11:39 am by naknak

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

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

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

» FlashLight Script
Touched event EmptyJanuary 1st 2014, 2:11 pm by m27frogy

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

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

» Improve Coding
Touched event EmptyOctober 26th 2013, 1:12 pm by pook03

» Simple Button
Touched event EmptySeptember 1st 2013, 6:19 pm by branefreez


 

 Touched event

Go down 
+2
naknak
slayer9365
6 posters
Go to page : 1, 2  Next
AuthorMessage
Guest
Guest
avatar



Touched event Empty
PostSubject: Touched event   Touched event EmptyAugust 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
slayer9365


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

Touched event Empty
PostSubject: Re: Touched event   Touched event EmptyAugust 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
avatar



Touched event Empty
PostSubject: Re: Touched event   Touched event EmptyAugust 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
slayer9365


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

Touched event Empty
PostSubject: Re: Touched event   Touched event EmptyAugust 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
avatar



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

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


Posts : 878
Join date : 2010-07-30

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

It will disappear
Back to top Go down
Guest
Guest
avatar



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

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


Posts : 878
Join date : 2010-07-30

Touched event Empty
PostSubject: Re: Touched event   Touched event EmptyJanuary 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
blueymaddog


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

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

naknak is right.
Back to top Go down
naknak
Administrator
Administrator
naknak


Posts : 878
Join date : 2010-07-30

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

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


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

Touched event Empty
PostSubject: Re: Touched event   Touched event EmptyJanuary 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)
Back to top Go down
Guest
Guest
avatar



Touched event Empty
PostSubject: Re: Touched event   Touched event EmptyJanuary 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
slayer9365


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

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

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



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

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


Posts : 878
Join date : 2010-07-30

Touched event Empty
PostSubject: Re: Touched event   Touched event EmptyJanuary 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
avatar


Posts : 393
Join date : 2011-01-17

Touched event Empty
PostSubject: Re: Touched event   Touched event EmptyJanuary 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
myrco919


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

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

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


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

Touched event Empty
PostSubject: Re: Touched event   Touched event EmptyJanuary 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)
Back to top Go down
slayer9365
Expert Scripter
Expert Scripter
slayer9365


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

Touched event Empty
PostSubject: Re: Touched event   Touched event EmptyJanuary 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
blueymaddog


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

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

but what if it isn't anchored and humanoid isn't renamed? lol :P
Back to top Go down
naknak
Administrator
Administrator
naknak


Posts : 878
Join date : 2010-07-30

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

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


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

Touched event Empty
PostSubject: Re: Touched event   Touched event EmptyJanuary 27th 2011, 2:27 am

lol.
Back to top Go down
ninga95
Administrator
Administrator
ninga95


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

Touched event Empty
PostSubject: Re: Touched event   Touched event EmptyFebruary 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
myrco919


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

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

Mistakes everywhere!

Back to top Go down
naknak
Administrator
Administrator
naknak


Posts : 878
Join date : 2010-07-30

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

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





Touched event Empty
PostSubject: Re: Touched event   Touched event Empty

Back to top Go down
 
Touched event
Back to top 
Page 1 of 2Go to page : 1, 2  Next

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