Fatalizer
|
  |
| Joined: 28 Aug 2011 |
| Total Posts: 1520 |
|
|
| 12 Sep 2014 02:26 PM |
Hello, I was making my script. I wanned it to remove a Gui which is in the PlayerGui. But I wanned to remove it on touch.. Here is my script I have so far;
script.Parent.Touched:connect(function(Touch) Touch.Parent.PlayerGui.SG:remove() end)
Could someone fix, please ?
~ I don't rekt kids, I eat them ~ |
|
|
| Report Abuse |
|
|
Nyxis
|
  |
| Joined: 15 Nov 2012 |
| Total Posts: 3374 |
|
|
| 12 Sep 2014 02:27 PM |
Player = game.Players:GetPlayerFromCharacter(Touch.Parent) Player.PlayerGui.SG:Destroy() -- ':remove()' isn't recommended for use
somethin like that |
|
|
| Report Abuse |
|
|
Fatalizer
|
  |
| Joined: 28 Aug 2011 |
| Total Posts: 1520 |
|
|
| 12 Sep 2014 02:30 PM |
This did not work. :/ Thanks for trying to help, tho.
~ I don't rekt kids, I eat them ~ |
|
|
| Report Abuse |
|
|
|
| 12 Sep 2014 02:30 PM |
Using the above's code, the correct code would be:
script.Parent.Touched:connect(function(hit) Player = hit.Parent:GetPlayerFromCharacter() Player.PlayerGui.SG:Destroy()--Don't use remove. It may not work. Stay safe with :Destroy() end) |
|
|
| Report Abuse |
|
|
Fatalizer
|
  |
| Joined: 28 Aug 2011 |
| Total Posts: 1520 |
|
|
| 12 Sep 2014 02:31 PM |
Also, this did not work.
~ I don't rekt kids, I eat them ~ |
|
|
| Report Abuse |
|
|
|
| 12 Sep 2014 02:34 PM |
script.Parent.Touched:connect(function(Touch) pcall(function() game.Players:GetPlayerFromCharacter(Touch.Parent).PlayerGui.SG:remove() end) end)
|
|
|
| Report Abuse |
|
|
Nyxis
|
  |
| Joined: 15 Nov 2012 |
| Total Posts: 3374 |
|
|
| 12 Sep 2014 02:37 PM |
ew pcall, super inefficient.
also, mine would work. if OP knew how to put two and two together
script.Parent.Touched:connect(function(Touch) if Touch.Parent:findFirstChild("Humanoid") then Player = game.Players:GetPlayerFromCharacter(Touch.Parent) if Player.PlayerGui:findFirstChild("SG") then game.Debris:AddItem(Player.PlayerGui.SG, 0) end end end) |
|
|
| Report Abuse |
|
|
Nyxis
|
  |
| Joined: 15 Nov 2012 |
| Total Posts: 3374 |
|
|
| 12 Sep 2014 02:38 PM |
| also a check to see if Player is actually a player might be necessary, if you have something else with a humanoid that might possible touch it. |
|
|
| Report Abuse |
|
|
Nyxis
|
  |
| Joined: 15 Nov 2012 |
| Total Posts: 3374 |
|
| |
|
|
| 12 Sep 2014 02:39 PM |
| Why would mine be inefficient? |
|
|
| Report Abuse |
|
|
Nyxis
|
  |
| Joined: 15 Nov 2012 |
| Total Posts: 3374 |
|
|
| 12 Sep 2014 02:41 PM |
| pcall is the lazy man's way to prevent errors, in some cases it may be required. but in this case you can just throw in an if statement or two |
|
|
| Report Abuse |
|
|
Fatalizer
|
  |
| Joined: 28 Aug 2011 |
| Total Posts: 1520 |
|
|
| 12 Sep 2014 02:41 PM |
@Nyxis
It worked great ! Thanks ! But could you define the script to me ? I could this later on, when I finished this project.
~ I don't rekt kids, I eat them ~ |
|
|
| Report Abuse |
|
|
| |
|
Fatalizer
|
  |
| Joined: 28 Aug 2011 |
| Total Posts: 1520 |
|
|
| 12 Sep 2014 02:44 PM |
@super10099
Yours worked perfectly also, I jut don't know how to adjut pcall, I know what it is.. "Protect Call", if I still remember it from the older days. Hehe
~ I don't rekt kids, I eat them ~ |
|
|
| Report Abuse |
|
|
Nyxis
|
  |
| Joined: 15 Nov 2012 |
| Total Posts: 3374 |
|
|
| 12 Sep 2014 02:44 PM |
um
script.Parent.Touched:connect(function(Touch) if Touch.Parent:findFirstChild("Humanoid") then --checks if humanoid exists Player = game.Players:GetPlayerFromCharacter(Touch.Parent) --sets the player from Touch.Parent if Player.PlayerGui:findFirstChild("SG") then --checks to see if 'SG' exists game.Debris:AddItem(Player.PlayerGui.SG, 0) --adds 'SG' to Debris end end end) |
|
|
| Report Abuse |
|
|
Fatalizer
|
  |
| Joined: 28 Aug 2011 |
| Total Posts: 1520 |
|
|
| 12 Sep 2014 02:53 PM |
What is "Debris" ?
~ I don't rekt kids, I eat them ~ |
|
|
| Report Abuse |
|
|
iiEssence
|
  |
| Joined: 18 Jun 2014 |
| Total Posts: 3467 |
|
|
| 12 Sep 2014 02:54 PM |
Service that is used to clear instances
I call it the infinite-depth dumpster |
|
|
| Report Abuse |
|
|
Nyxis
|
  |
| Joined: 15 Nov 2012 |
| Total Posts: 3374 |
|
|
| 12 Sep 2014 02:55 PM |
http://wiki.roblox.com/index.php?title=AddItem_(Method)
I usually only use this to remove items, because there's a lifetime to how long before it gets remove, and it doesn't pause the script. |
|
|
| Report Abuse |
|
|
Fatalizer
|
  |
| Joined: 28 Aug 2011 |
| Total Posts: 1520 |
|
|
| 12 Sep 2014 03:02 PM |
So it's actually really useful.. Hmm.
~ I don't rekt kids, I eat them ~ |
|
|
| Report Abuse |
|
|