pokesal
|
  |
| Joined: 29 Oct 2010 |
| Total Posts: 10751 |
|
|
| 08 Jul 2011 03:41 AM |
I am new to scripting. I made this script:
local brick = Instance.new ("Part") function onTouched(Hit) brick.Transparency = 1 wait(2) brick.Transparency = 0 end end
game.Workspace.Part: connect onTouched(Hit)
Whenever I hit the brick, it doesn't perform the function. Can someone help me and show me the corrected script? Thank you. |
|
|
| Report Abuse |
|
|
OBFAlt
|
  |
| Joined: 06 Jul 2011 |
| Total Posts: 35 |
|
|
| 08 Jul 2011 03:46 AM |
local brick = Instance.new("Brick") brick.Parent = Workspace function touch(hit) brick.Transparency = 1 wait(2) brick.Transparency = 0 end brick.Touched:connect(touch)
That will make a new brick in the Workspace, and make in invisible then visible again when you touch it. |
|
|
| Report Abuse |
|
|
pokesal
|
  |
| Joined: 29 Oct 2010 |
| Total Posts: 10751 |
|
|
| 08 Jul 2011 03:50 AM |
Where do I put the script? Because putting it in the brick doesn't work.
|
|
|
| Report Abuse |
|
|
OBFAlt
|
  |
| Joined: 06 Jul 2011 |
| Total Posts: 35 |
|
|
| 08 Jul 2011 03:52 AM |
You already have the brick?
script.Parent.Touched:connect(function() script.Parent.Transparency = 1 wait(2) script.Parent.Transparency = 0 end) |
|
|
| Report Abuse |
|
|
pokesal
|
  |
| Joined: 29 Oct 2010 |
| Total Posts: 10751 |
|
|
| 08 Jul 2011 03:53 AM |
| Yes. I already have the brick. |
|
|
| Report Abuse |
|
|
OBFAlt
|
  |
| Joined: 06 Jul 2011 |
| Total Posts: 35 |
|
|
| 08 Jul 2011 03:55 AM |
| Then put my second one in the brick. |
|
|
| Report Abuse |
|
|
pokesal
|
  |
| Joined: 29 Oct 2010 |
| Total Posts: 10751 |
|
|
| 08 Jul 2011 03:58 AM |
| Thanks. It works. Can you explain the first line of the script? |
|
|
| Report Abuse |
|
|
|
| 08 Jul 2011 03:59 AM |
| The first line is a Connection line, Connection lines are the ones that make the script complete if you have a function |
|
|
| Report Abuse |
|
|
pokesal
|
  |
| Joined: 29 Oct 2010 |
| Total Posts: 10751 |
|
|
| 08 Jul 2011 04:01 AM |
| Okay. But doesn't the connection line usually go at the end of the script? |
|
|
| Report Abuse |
|
|
pokesal
|
  |
| Joined: 29 Oct 2010 |
| Total Posts: 10751 |
|
|
| 08 Jul 2011 04:03 AM |
Also, I made this script to change its reflectance:
script.Parent.Touched:connect(function() script.Parent.Reflectance = 1 wait(2) script.Parent.Reflectance = 0 end)
Just change "Transparency" to "Reflectance" and it works. |
|
|
| Report Abuse |
|
|
OBFAlt
|
  |
| Joined: 06 Jul 2011 |
| Total Posts: 35 |
|
|
| 08 Jul 2011 04:13 AM |
| Oh, sorry. It's an anonymous function. It's the connection line and the function all mixed into one. :) |
|
|
| Report Abuse |
|
|
pokesal
|
  |
| Joined: 29 Oct 2010 |
| Total Posts: 10751 |
|
|
| 08 Jul 2011 04:17 AM |
Can you still write it like this:
function onTouched(hit) script.Parent.Transparency = 1 wait(2) script.Parent.Transparency = 0 end script.Parent.Touched:connect onTouched
|
|
|
| Report Abuse |
|
|
| |
|
MassaIII
|
  |
| Joined: 16 Mar 2008 |
| Total Posts: 72 |
|
|
| 08 Jul 2011 05:25 AM |
function onTouched(hit) script.Parent.Transparency = 1 wait(2) script.Parent.Transparency = 0 end script.Parent.Touched:connect(onTouched) --You forgot the brackets here.
|
|
|
| Report Abuse |
|
|
pokesal
|
  |
| Joined: 29 Oct 2010 |
| Total Posts: 10751 |
|
|
| 08 Jul 2011 06:47 AM |
| Yeah. I know. Also, is there a such thing as onClick? |
|
|
| Report Abuse |
|
|
|
| 08 Jul 2011 06:49 AM |
Yeah.
script.Parent.ClickDetector.MouseClick:connect(function() script.Parent.Reflectance = 1 wait(2) script.Parent.Reflectance = 0 end)
|
|
|
| Report Abuse |
|
|
zeke505
|
  |
| Joined: 26 May 2008 |
| Total Posts: 15765 |
|
|
| 08 Jul 2011 06:49 AM |
| Yes, for click detectors. But it does not return the player who clicked it. |
|
|
| Report Abuse |
|
|
pokesal
|
  |
| Joined: 29 Oct 2010 |
| Total Posts: 10751 |
|
|
| 08 Jul 2011 06:50 AM |
| So how would I make the brick change it's Transparency by clicking it? |
|
|
| Report Abuse |
|
|
pokesal
|
  |
| Joined: 29 Oct 2010 |
| Total Posts: 10751 |
|
| |
|
myrco919
|
  |
| Joined: 12 Jun 2009 |
| Total Posts: 13241 |
|
| |
|
zeke505
|
  |
| Joined: 26 May 2008 |
| Total Posts: 15765 |
|
|
| 08 Jul 2011 06:52 AM |
| The same way you did using the touched function, just don't have an argument. |
|
|
| Report Abuse |
|
|
pokesal
|
  |
| Joined: 29 Oct 2010 |
| Total Posts: 10751 |
|
|
| 08 Jul 2011 06:55 AM |
| Okay. I got it. I thank everyone for their help. |
|
|
| Report Abuse |
|
|
myrco919
|
  |
| Joined: 12 Jun 2009 |
| Total Posts: 13241 |
|
| |
|
myrco919
|
  |
| Joined: 12 Jun 2009 |
| Total Posts: 13241 |
|
| |
|