|
| 06 Aug 2015 03:18 PM |
You know how when your gun is equipped or unequipped the gun is in different places right? That is my problem.
I tried two scripts to solve this. 1 for the gun in the character, and 1 for the gun being in the player's backpack.
The purpose of the script is to remove the gun when you stand up after you were sitting down from a certain seat.
Is there anything wrong with these scripts?
--When gun is equipped while true do wait() if script.Parent.Parent:FindFirstChild("Humanoid").Sit == false then script.Parent:remove() end end
--When gun is unequipped while true do wait() if script.Parent.Parent.Parent:FindFirstChild("Character"):FindFirstChild("Humanoid").Sit == false then script.Parent:remove() end end
I need an answer immediately.COME ON NO ONE IS ANSWERING! |
|
|
| Report Abuse |
|
|
Iterum
|
  |
| Joined: 30 Jan 2009 |
| Total Posts: 1982 |
|
|
| 06 Aug 2015 03:22 PM |
You can't use FindFirstChild like that. Also, use Destroy() not Remove().
You basically ignore the FindFirstChild() and it'll still error if it doesn't eist.
Also you can use the "not" operator instead of == false.
-ChiefDelta/Discommodate/iC7G/Vulnerite + 100 other accounts |
|
|
| Report Abuse |
|
|
DogeKip
|
  |
| Joined: 06 Mar 2011 |
| Total Posts: 6860 |
|
|
| 06 Aug 2015 03:24 PM |
Because you aren't testing if the gun is there, you will get an error no matter what because you are running both, assuming these are two different scripts. Try this: while true do wait() if script.Parent.Parent:FindFirstChild("Humanoid") then if script.Parent.Parent:FindFirstChild("Humanoid").Sit == false then script.Parent:Remove() end else if script.Parent.Parent.Parent.Character:FindFirstChild("Humanoid") then if script.Parent.Parent.Parent.Character:FindFirstChild("Humanoid").Sit == false then script.Parent:Remove() end end end end
[DATA EXPUNGED] |
|
|
| Report Abuse |
|
|
Iterum
|
  |
| Joined: 30 Jan 2009 |
| Total Posts: 1982 |
|
|
| 06 Aug 2015 03:25 PM |
Once again DogeKip you can't use FindFirstChild like that and you don't use Remove() and you can use the not operator.
-ChiefDelta/Discommodate/iC7G/Vulnerite + 100 other accounts |
|
|
| Report Abuse |
|
|
FIares
|
  |
| Joined: 07 Nov 2010 |
| Total Posts: 641 |
|
|
| 06 Aug 2015 03:25 PM |
If both of those loops are in the same code, without coroutines, only the first one will run.
Check out my in-game scripting tutorial! [ 279086510 ] |
|
|
| Report Abuse |
|
|
Iterum
|
  |
| Joined: 30 Jan 2009 |
| Total Posts: 1982 |
|
|
| 06 Aug 2015 03:26 PM |
"If both of those loops are in the same code, without coroutines, only the first one will run."
He didn't specify but I'd bet he's using these inside the Equipped and Unequipped events.
-ChiefDelta/Discommodate/iC7G/Vulnerite + 100 other accounts |
|
|
| Report Abuse |
|
|
FIares
|
  |
| Joined: 07 Nov 2010 |
| Total Posts: 641 |
|
|
| 06 Aug 2015 03:27 PM |
Why use loops inside events... They're events...
Check out my in-game scripting tutorial! [ 279086510 ] |
|
|
| Report Abuse |
|
|
Iterum
|
  |
| Joined: 30 Jan 2009 |
| Total Posts: 1982 |
|
|
| 06 Aug 2015 03:27 PM |
I could ask "why" about everything OP is doing in his code.
All of our code makes no sense when we're newer to scripting. It's part of the learning process.
-ChiefDelta/Discommodate/iC7G/Vulnerite + 100 other accounts |
|
|
| Report Abuse |
|
|
|
| 06 Aug 2015 03:33 PM |
| @DogeKip Thx I don't know what you did but it worked. Can you tell me what you changed in there? |
|
|
| Report Abuse |
|
|
DogeKip
|
  |
| Joined: 06 Mar 2011 |
| Total Posts: 6860 |
|
|
| 06 Aug 2015 03:35 PM |
You had to check if the humanoid exists, and you were running two loops but only the first was running.
[DATA EXPUNGED] |
|
|
| Report Abuse |
|
|