generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: How do I use the onTouched function?

Previous Thread :: Next Thread 
biker6700 is not online. biker6700
Joined: 22 Mar 2010
Total Posts: 1515
02 Nov 2011 04:02 PM
[Beginer Scripter]

How do I use it because I am learning how to and I am trying to touch a brick and make it change every color in the colorpad but I don't know how to use the onTouch function.
Report Abuse
biker6700 is not online. biker6700
Joined: 22 Mar 2010
Total Posts: 1515
02 Nov 2011 04:03 PM
Beginner*
Report Abuse
TheWisest is not online. TheWisest
Joined: 11 Nov 2010
Total Posts: 7345
02 Nov 2011 04:05 PM
Simple:

function onTouched(hit) --Calls the function, you can name it anything though. E.G 'onBanana(hit)'
-Stuff Stuff
end
script.Parent.Touched:connect(onTouched) --Executes the function.
Report Abuse
Willingroblox123 is not online. Willingroblox123
Joined: 18 Jan 2010
Total Posts: 6872
02 Nov 2011 04:07 PM
Like TheWisest said, that is how you use it, but if you change the name of the function you also have to change the

    script.Parent.Touched:connect(onTouched) --You have to change "onTouched" to your function name.
Report Abuse
biker6700 is not online. biker6700
Joined: 22 Mar 2010
Total Posts: 1515
02 Nov 2011 04:07 PM
Thanks!
Report Abuse
TheWisest is not online. TheWisest
Joined: 11 Nov 2010
Total Posts: 7345
02 Nov 2011 04:08 PM
@Willing,


I was just about to mention that. :P
Report Abuse
biker6700 is not online. biker6700
Joined: 22 Mar 2010
Total Posts: 1515
02 Nov 2011 04:09 PM
So I just write the script where it says -stuff stuff
Report Abuse
TheWisest is not online. TheWisest
Joined: 11 Nov 2010
Total Posts: 7345
02 Nov 2011 04:13 PM
Yeah pretty much...... if you have any more errors, don't be afraid to ask. :)
Report Abuse
biker6700 is not online. biker6700
Joined: 22 Mar 2010
Total Posts: 1515
03 Nov 2011 11:19 AM
Would this work?

function onTouched("Wedge")

wait(1)
game.Workspace.Wedge.BrickColor = BrickColor.new("Bright Yellow")

wait(1)
game.Workspace.Wedge.BrickColor = BrickColor.new("Black")

wait(1)
game.Workspace.Wedge.BrickColor = BrickColor.new("Red")

end

script.Parent.Touched:connect(onTouched)
Report Abuse
TheWisest is not online. TheWisest
Joined: 11 Nov 2010
Total Posts: 7345
03 Nov 2011 12:43 PM
Eh, no.....

When you call the function, there really is no need to put the object in that line.

So it should just be:

function onTouched(hit)
wait(1)
game.Workspace.Wedge.BrickColor = BrickColor.new("Bright Yellow")
wait(1)
game.Workspace.Wedge.BrickColor = BrickColor.new("Black")
wait(1)
game.Workspace.Wedge.BrickColor = BrickColor.new("Red")
end
script.Parent.Touched:connect(onTouched)

Report Abuse
Miro034 is not online. Miro034
Joined: 07 Oct 2009
Total Posts: 6568
03 Nov 2011 01:53 PM
@Above

I love beginner scripters :D
Report Abuse
Lightmaster9 is not online. Lightmaster9
Joined: 14 May 2009
Total Posts: 8659
03 Nov 2011 02:05 PM
Another way is:

-- this is in a brick! :D

part = workspace.Base

script.Parent.Touched:connect(function(hit,part)
hit:Remove()
part:Remove()
end
Report Abuse
biker6700 is not online. biker6700
Joined: 22 Mar 2010
Total Posts: 1515
03 Nov 2011 05:07 PM
Ok I tryed it and the Output said this (Touched is not a valid member of Workspace)
Report Abuse
biker6700 is not online. biker6700
Joined: 22 Mar 2010
Total Posts: 1515
03 Nov 2011 05:14 PM
I fixed it forgot to put the script into the Wedge part. :) Stupid mistake.
Report Abuse
biker6700 is not online. biker6700
Joined: 22 Mar 2010
Total Posts: 1515
04 Nov 2011 06:21 PM
[Beginner Scripter]

Would this work in a part?


--Made by Biker6700

Explode = Instance.new("Explosion")

function onTouched(hit)
Explode = Instance.new("Explosion")
Explode.BlastRadius = 12
Explode.BlastPressure = 1000
Explode.Position = script.Parent.Position
Explode.Parent = game.Workspace
script.Parent.Transparency = 0
connection:disconnect()
end

script.Parent.Touched:connect(onTouched)
Report Abuse
xV3m0GirLVx is not online. xV3m0GirLVx
Joined: 24 Sep 2011
Total Posts: 91
04 Nov 2011 06:23 PM
game.Workspace.Part.onTouch:connect (function)) print("ow") end)

put the name of the brick were Part is in the script. then put function and then put what you want then end)
Report Abuse
GigsD4X is online. GigsD4X
Joined: 06 Jun 2008
Total Posts: 3794
04 Nov 2011 06:28 PM
^ Actually that should be
game.Workspace.Part.Touched:connect(function() print("ow") end)

^^ Yes it would.
Report Abuse
Miro034 is not online. Miro034
Joined: 07 Oct 2009
Total Posts: 6568
04 Nov 2011 06:54 PM
I see that your improving very quick :D
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image