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 » Scripters
Home Search
 

Re: Double key press not working correctly

Previous Thread :: Next Thread 
Raidorz is not online. Raidorz
Joined: 28 Apr 2011
Total Posts: 5221
31 May 2015 01:19 PM
I created a script where to parts welded to the arm appear when I press a key, but when the player presses the key a second time the welded parts are supposed to be destroyed/removed/added into the debris. What happens is that the parts stay I tried this.
if key == "e" and timespressed = 0
timespressed = timespressed + 1

-- huge chunk of codes, indexing the parts Leftwing and Rightwing

if key == "e" and timespressed = 1
Lwing:Destroy()
Rwing:Destroy()

I get this error,
Players.Player.Backpack.LocalScript:62: attempt to index global 'Lwing' (a nil value)

I indexed the Lwing and Rwing before the else if statement, I'm kind of stuck now.
Report Abuse
amanda is not online. amanda
Joined: 21 Nov 2006
Total Posts: 5925
31 May 2015 01:32 PM
1. KeyDown and KeyUp are depreciated. I'm assuming that's what you are using.

local presses = 0

local UIS = game:GetService("UserInputService")

UIS.InputBegan:connect(function(input, gameProcessedEvent)
if not gameProcessedEvent then
if input.KeyCode == Enum.KeyCode.E then
presses = presses + 1
if presses == 1 then

elseif presses == 2 then

end
end
end
end)

2. You need to define the wings before any of the if statements.
Report Abuse
Raidorz is not online. Raidorz
Joined: 28 Apr 2011
Total Posts: 5221
31 May 2015 01:32 PM
Where do I need to index the Lwing and the Rwing so that I can destroy Lwing and Rwing because it isn't working.
Report Abuse
Raidorz is not online. Raidorz
Joined: 28 Apr 2011
Total Posts: 5221
31 May 2015 01:34 PM
The thing is I'm cloning the Lwing and the Rwing from the server storage.
Report Abuse
amanda is not online. amanda
Joined: 21 Nov 2006
Total Posts: 5925
31 May 2015 01:35 PM
--DEFINE THEM UP HERE

local presses = 0

local UIS = game:GetService("UserInputService")

UIS.InputBegan:connect(function(input, gameProcessedEvent)
if not gameProcessedEvent then
if input.KeyCode == Enum.KeyCode.E then
presses = presses + 1
if presses == 1 then

elseif presses == 2 then

end
end
end
end)
Report Abuse
Raidorz is not online. Raidorz
Joined: 28 Apr 2011
Total Posts: 5221
31 May 2015 01:59 PM
Yeah, it's fixed now. But what happens is if I redo the WHOLE function a second time it is gonna lock the Right/Left wing because it only clones once

Rwing = --indexing:clone()
Lwing = --indexing:clone()

function
if key == key etc

-- all the codes
Report Abuse
Raidorz is not online. Raidorz
Joined: 28 Apr 2011
Total Posts: 5221
31 May 2015 02:19 PM
So how to make it so that I will be able to clone each time instead of only one time?

So this is pretty difficult to deal with, if I put it before the function, the whole function will work only ONCE. Because I clone them once from the server storage.

But if I put it after the function, the parts I welded to the arms won't be destroyed.

Does anyone have experience with this kind of stuff, I'm stuck.
Report Abuse
Raidorz is not online. Raidorz
Joined: 28 Apr 2011
Total Posts: 5221
31 May 2015 02:29 PM
-- Fixed.

Since the parts would be cloned inside the workspace anyway. I decided to define Lwing and Rwing again inside the elseif statement but this time place the Lwing and Rwing inside the Workspace, so when the Rwing and Lwing get cloned and put inside the workspace I destroy them from there.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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