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: For some reason the gun isn't getting destroyed

Previous Thread :: Next Thread 
laughablehaha is not online. laughablehaha
Joined: 19 Apr 2012
Total Posts: 2495
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 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. 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
laughablehaha is not online. laughablehaha
Joined: 19 Apr 2012
Total Posts: 2495
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 is not online. 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
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