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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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 |
|
|