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: Is this correct?

Previous Thread :: Next Thread 
LordOreo is not online. 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 is not online. LordOreo
Joined: 17 Feb 2011
Total Posts: 4763
04 Jul 2013 07:09 PM
bump
Report Abuse
goalzero is not online. goalzero
Joined: 29 Sep 2010
Total Posts: 132
04 Jul 2013 07:14 PM
Is this the whole code?
Report Abuse
LordOreo is not online. 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 is not online. 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 is not online. 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 is not online. 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
dennis96411 is not online. dennis96411
Joined: 06 Mar 2009
Total Posts: 1079
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 is not online. 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 is not online. 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 is not online. 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 is not online. 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
dennis96411 is not online. dennis96411
Joined: 06 Mar 2009
Total Posts: 1079
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 is not online. 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 is not online. LordOreo
Joined: 17 Feb 2011
Total Posts: 4763
04 Jul 2013 07:39 PM
The script is in the gun
Report Abuse
dennis96411 is not online. dennis96411
Joined: 06 Mar 2009
Total Posts: 1079
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 is not online. 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
dennis96411 is not online. dennis96411
Joined: 06 Mar 2009
Total Posts: 1079
04 Jul 2013 07:48 PM
Is "sp" declared?
Report Abuse
LordOreo is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. goalzero
Joined: 29 Sep 2010
Total Posts: 132
04 Jul 2013 08:08 PM
The Main Tool is your gun or whatever
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