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: Global functions

Previous Thread :: Next Thread 
Xtreme101 is not online. Xtreme101
Joined: 03 Jan 2009
Total Posts: 4385
19 Jul 2013 05:09 PM
My global functions seemed to have stopped working. They're really old and the script hasn't been updated in a long time. What is the current/best method?
Report Abuse
ZachBloxx is not online. ZachBloxx
Joined: 26 Jun 2013
Total Posts: 2833
19 Jul 2013 05:10 PM
_G.NewFunction = (function()
--blah
end)

-- There are many methods, but I use this.
Report Abuse
Xtreme101 is not online. Xtreme101
Joined: 03 Jan 2009
Total Posts: 4385
19 Jul 2013 05:12 PM
Thanks. It was different.
Report Abuse
Christbru01 is not online. Christbru01
Joined: 03 Apr 2010
Total Posts: 649
19 Jul 2013 05:16 PM
function name()

end

_G.FuncName = coroutine.wrap(name)

Much better version because it wraps it into a coroutine... and I like coroutines because they will not break a script if it errors...
Report Abuse
Xtreme101 is not online. Xtreme101
Joined: 03 Jan 2009
Total Posts: 4385
19 Jul 2013 05:19 PM
Thanks, but now I have a new problem. No matter what I do, I cannot seem to get the script to remove a model. Here's the general concept:

_G.destroy = (function(model, name)
model:destroy()
end)

Not sure if the ROBLOX Engine is limiting this or what, but it only works 1/10 times.
Report Abuse
Christbru01 is not online. Christbru01
Joined: 03 Apr 2010
Total Posts: 649
19 Jul 2013 05:24 PM
_G.destroy = coroutine.wrap(function(model,name)
model:Destroy()
delay(0.1,function() if model and model.Parent then game:service('Debris'):AddItem(model,0) end end)
end)

This is one way to make it inside a coroutin [better!] aswell as it has a fallback incase Destroy doesn't work...
Report Abuse
Xtreme101 is not online. Xtreme101
Joined: 03 Jan 2009
Total Posts: 4385
19 Jul 2013 05:32 PM
Okay Christbru, I'll do it your way. Lol
Report Abuse
Christbru01 is not online. Christbru01
Joined: 03 Apr 2010
Total Posts: 649
19 Jul 2013 05:47 PM
Lol, Alrighty cx
Main reason why I recommend using coroutine.wrap is because with a coroutine you can call it multiple times and they'll all run along side eachother, where as with usual functions you have to wait until the function is done before trying to use it again... aswell as with a coroutine if there is an error inside of the coroutine it will break itself, not the script, and better yet it can be called again without a problem [unless the error stops it again]
Report Abuse
Xtreme101 is not online. Xtreme101
Joined: 03 Jan 2009
Total Posts: 4385
19 Jul 2013 05:53 PM
"Multiple times"

17:36:50.772 - Workspace.Weapon.DamageScript:45: cannot resume dead coroutine
17:36:50.773 - Script "Workspace.Weapon.DamageScript", Line 45
17:36:50.774 - stack end
Report Abuse
Xtreme101 is not online. Xtreme101
Joined: 03 Jan 2009
Total Posts: 4385
19 Jul 2013 06:00 PM
Christbru01. Bump.
Report Abuse
Xtreme101 is not online. Xtreme101
Joined: 03 Jan 2009
Total Posts: 4385
19 Jul 2013 06:18 PM
Bump bump.
Report Abuse
Xtreme101 is not online. Xtreme101
Joined: 03 Jan 2009
Total Posts: 4385
19 Jul 2013 06:28 PM
Bump bump bump.
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