|
| 27 Nov 2013 05:59 PM |
I am making a game, I made a switch when players touch it, a light flashes on and plays a clicking noise. Not exactly sure how to do it.
function onTouched()
Light = script.Parent NewLight = Instance.new("PointLight",Light) game.Workspace.Sound:play() end
Light.Touched:connect(onTouched)
How do you do this?! It is supposed to Play a clicking sound and turn on a light when Touched, also, when you touch it again, it turns off. I am stumped. Normally, when I type this much I get no replies ): |
|
|
| Report Abuse |
|
|
BruceAB12
|
  |
| Joined: 19 Jan 2012 |
| Total Posts: 3238 |
|
|
| 27 Nov 2013 06:02 PM |
Use a debounce, then just set the pointlight to enabled or disabled according to the debounce's value
E.G:
debounce = false
if debounce then NewLight.Enabled = true elseif not debounce then NewLight.Enabled = false end
|
|
|
| Report Abuse |
|
|
|
| 27 Nov 2013 06:05 PM |
| Hope it goes at the top of the script. |
|
|
| Report Abuse |
|
|
|
| 27 Nov 2013 06:09 PM |
Doesn't work. I wanted this function for a more realistic game feature. Output: Global "NewLight" a nil value
Should I try the bottom of the script? |
|
|
| Report Abuse |
|
|
BruceAB12
|
  |
| Joined: 19 Jan 2012 |
| Total Posts: 3238 |
|
|
| 27 Nov 2013 06:10 PM |
.... Of course it isn't going to work that was just an example. |
|
|
| Report Abuse |
|
|
| |
|
BruceAB12
|
  |
| Joined: 19 Jan 2012 |
| Total Posts: 3238 |
|
|
| 27 Nov 2013 06:17 PM |
Light = script.Parent debounce = false NewLight = Instance.new("PointLight",Light) NewLight.Enabled = false
Light.Touched:connect(function() Game.Workspace.Sound:Play() if debounce then debounce = false NewLight.Enabled = false elseif not debounce then debounce = true NewLight.Enabled = true end end)
That should work. |
|
|
| Report Abuse |
|
|
Azarth
|
  |
| Joined: 17 Aug 2012 |
| Total Posts: 2760 |
|
|
| 27 Nov 2013 06:18 PM |
| http://www.roblox.com/light-item?id=136790746 |
|
|
| Report Abuse |
|
|
| |
|