LordOreo
|
  |
| Joined: 17 Feb 2011 |
| Total Posts: 4763 |
|
|
| 04 Jul 2013 07:07 PM |
I tried putting this in a tool of a gun to make it turn on/off a spotlight in a block I inserted a script and it still isn't working Can anyone help me with this?: function onKeyDown(key,mouse) if key=="l" then if on==false then sp.DL.SpotLight.Enabled=true on=true elseif on==true then sp.DL.Spotlight.Enabled=false end end end
|
|
|
| Report Abuse |
|
|
LordOreo
|
  |
| Joined: 17 Feb 2011 |
| Total Posts: 4763 |
|
| |
|
goalzero
|
  |
| Joined: 29 Sep 2010 |
| Total Posts: 132 |
|
| |
|
LordOreo
|
  |
| Joined: 17 Feb 2011 |
| Total Posts: 4763 |
|
|
| 04 Jul 2013 07:15 PM |
| I tried putting this part in the main script with all the gun scripts but it just broke the gun. |
|
|
| Report Abuse |
|
|
goalzero
|
  |
| Joined: 29 Sep 2010 |
| Total Posts: 132 |
|
|
| 04 Jul 2013 07:17 PM |
function onKeyDown(key) if key=="l" then if on==false then sp.DL.SpotLight.Enabled=true on=true elseif on==true then sp.DL.Spotlight.Enabled=false end end end |
|
|
| Report Abuse |
|
|
goalzero
|
  |
| Joined: 29 Sep 2010 |
| Total Posts: 132 |
|
|
| 04 Jul 2013 07:17 PM |
| There is no mouse returned it the KeyDown event. |
|
|
| Report Abuse |
|
|
LordOreo
|
  |
| Joined: 17 Feb 2011 |
| Total Posts: 4763 |
|
|
| 04 Jul 2013 07:18 PM |
| Do I put that on a localScript? I'm new to scripting. :c |
|
|
| Report Abuse |
|
|
|
| 04 Jul 2013 07:21 PM |
Is that the entire script? It seems you haven't called the function.
script.Parent.Equipped:connect(function(Key) --Change "script.Parent" to whatever the tool is" Key.KeyDown:connect(function(Key) if Key == "I" then --Is this an i or L? if on then sp.DL.Spotlight.Enabled = false on = false else sp.DL.Spotlight.Enabled = true on = true end end end) end) |
|
|
| Report Abuse |
|
|
goalzero
|
  |
| Joined: 29 Sep 2010 |
| Total Posts: 132 |
|
|
| 04 Jul 2013 07:22 PM |
Can I see the whole script?
Its hard for me to trace this. |
|
|
| Report Abuse |
|
|
LordOreo
|
  |
| Joined: 17 Feb 2011 |
| Total Posts: 4763 |
|
|
| 04 Jul 2013 07:28 PM |
unfortunately it did not work, thank you for trying though.
script.MP8.Equipped:connect(function(Key) --Do I change the script. part to what the script was called? Key.KeyDown:connect(function(Key) if Key == "l" then --It was an l if on then sp.DL.Spotlight.Enabled = false on = false else sp.DL.Spotlight.Enabled = true on = true end end end) end)
|
|
|
| Report Abuse |
|
|
LordOreo
|
  |
| Joined: 17 Feb 2011 |
| Total Posts: 4763 |
|
|
| 04 Jul 2013 07:28 PM |
The script of the gun? Or just the part of the keys such as the silencer? |
|
|
| Report Abuse |
|
|
goalzero
|
  |
| Joined: 29 Sep 2010 |
| Total Posts: 132 |
|
|
| 04 Jul 2013 07:31 PM |
| The script that contains the snip you gave us. |
|
|
| Report Abuse |
|
|
|
| 04 Jul 2013 07:37 PM |
"script.MP8.Equipped:connect(function(Key)" So the gun is INSIDE the script? Or is the script directly inside the gun? |
|
|
| Report Abuse |
|
|
LordOreo
|
  |
| Joined: 17 Feb 2011 |
| Total Posts: 4763 |
|
|
| 04 Jul 2013 07:37 PM |
| Oh I made that in a separate script because when i inserted that part of the script into the main gun script it broke the whole thing |
|
|
| Report Abuse |
|
|
LordOreo
|
  |
| Joined: 17 Feb 2011 |
| Total Posts: 4763 |
|
| |
|
|
| 04 Jul 2013 07:42 PM |
| So it should be "script.Parent.Equipped:connect(function(Key)" since the tool is the parent of the script. |
|
|
| Report Abuse |
|
|
LordOreo
|
  |
| Joined: 17 Feb 2011 |
| Total Posts: 4763 |
|
|
| 04 Jul 2013 07:44 PM |
So it would be: script.Parent.Equipped:connect(function(Key) Key.KeyDown:connect(function(Key) if Key == "l" then --It was an l if on then sp.DL.Spotlight.Enabled = false on = false else sp.DL.Spotlight.Enabled = true on = true end end end) end) ? |
|
|
| Report Abuse |
|
|
| |
|
LordOreo
|
  |
| Joined: 17 Feb 2011 |
| Total Posts: 4763 |
|
|
| 04 Jul 2013 07:48 PM |
| I'll pay 200 robux to whoever can help me :c |
|
|
| Report Abuse |
|
|
LordOreo
|
  |
| Joined: 17 Feb 2011 |
| Total Posts: 4763 |
|
|
| 04 Jul 2013 07:49 PM |
I can't script I just saw this in the main gun script: if key=="q" then if on==false then sp.Handle.Trigger:play() sp.MuzPart1.Transparency=0 sp.MuzPart2.Transparency=0 sp.Handle.Fire.Pitch=7.5 sp.Flash.Light.Enabled=false sp.Flash.Mesh.Scale=Vector3.new(0,0,0) on=true elseif on==true then sp.Handle.Trigger:play() sp.MuzPart1.Transparency=1 sp.MuzPart2.Transparency=1 sp.Handle.Fire.Pitch=1.1 sp.Flash.Light.Enabled=true sp.Flash.Mesh.Scale=Vector3.new(0.75,1,0.75) on=false end end end
and decided i should probably use sp |
|
|
| Report Abuse |
|
|
LordOreo
|
  |
| Joined: 17 Feb 2011 |
| Total Posts: 4763 |
|
|
| 04 Jul 2013 07:53 PM |
| Maybe I should put the script inside the brick containing the spot light |
|
|
| Report Abuse |
|
|
goalzero
|
  |
| Joined: 29 Sep 2010 |
| Total Posts: 132 |
|
|
| 04 Jul 2013 08:02 PM |
If you put this script inside a LocalScript inside the light brick it should work:
local MyMouse = game.Players.LocalPlayer:GetMouse() local Light = script.Parent:WaitForChild('SpotLight') --Change to name of light local Tool = script.Parent.Parent -- Make sure this is the main tool local Enabled = false local KeyCode = string.byte('l') -- KeyName MyMouse.KeyDown:connect(function(Key) if string.byte(Key) == KeyCode then Enabled = not Enabled Light.Enabled = Enabled end end)
|
|
|
| Report Abuse |
|
|
LordOreo
|
  |
| Joined: 17 Feb 2011 |
| Total Posts: 4763 |
|
|
| 04 Jul 2013 08:05 PM |
What do you mean make sure it is the main tool? Like script.Parent.MP8? |
|
|
| Report Abuse |
|
|
goalzero
|
  |
| Joined: 29 Sep 2010 |
| Total Posts: 132 |
|
|
| 04 Jul 2013 08:08 PM |
Well if its laid out like this
MP8 -LightPart --LocalScipt --SpotLight
then it would be: script.Parent
|
|
|
| Report Abuse |
|
|
goalzero
|
  |
| Joined: 29 Sep 2010 |
| Total Posts: 132 |
|
|
| 04 Jul 2013 08:08 PM |
| The Main Tool is your gun or whatever |
|
|
| Report Abuse |
|
|