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 » Scripting Helpers
Home Search
 

Re: Quick Script

Previous Thread :: Next Thread 
Fatalizer is not online. 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 is not online. 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 is not online. 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
fahmisack123 is not online. fahmisack123
Joined: 04 Jan 2013
Total Posts: 581
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 is not online. 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
super10099 is not online. super10099
Joined: 30 Jan 2010
Total Posts: 1102
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 is not online. 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 is not online. 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 is not online. Nyxis
Joined: 15 Nov 2012
Total Posts: 3374
12 Sep 2014 02:38 PM
possibly*
Report Abuse
super10099 is not online. super10099
Joined: 30 Jan 2010
Total Posts: 1102
12 Sep 2014 02:39 PM
Why would mine be inefficient?
Report Abuse
Nyxis is not online. 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 is not online. 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
super10099 is not online. super10099
Joined: 30 Jan 2010
Total Posts: 1102
12 Sep 2014 02:42 PM
Mine would work too..
Report Abuse
Fatalizer is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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