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: Help with globals?

Previous Thread :: Next Thread 
Zecrit is not online. Zecrit
Joined: 24 Jan 2013
Total Posts: 2618
13 Oct 2013 08:46 AM
I need to turn some scripts that should be used independently into globals to reduce overall lag.

Turn this into a global so I can see how it's done and I'll be fine from there:

-------------------

tool = game.Lighting: FindFirstChild(script.Parent.Tool.Value)

function onChildAdded(part)
local A = part.Part1.Parent
local B = game.Players:GetPlayerFromCharacter(A)
if (B.TeamColor == script.Parent.Parent.Parent.TeamColor.Value) then
local C = script.Parent.ModelTag:clone()
C.Value = script.Parent.Parent
C.Parent = A
local Tool = tool:clone()
Tool.Parent = B.Backpack
Tool.Ship.Value = script.Parent.Parent.Parent
Tool.TextureId = script.Parent.Parent.Parent.DataTable.ToolTexture.Value
local TG = Tool.TargetGui
TG.Parent = B.PlayerGui
else
A.Humanoid:TakeDamage(110)
end
end

function onChildRemoved(part)
local A = part.Part1.Parent
local B = game.Players:GetPlayerFromCharacter(A)
if (A:FindFirstChild("ModelTag")) then
A.ModelTag:remove()
end
local Tool = B.Backpack:FindFirstChild(script.Parent.Tool.Value)
if (Tool ~= nil) then
Tool: remove()
end
local TG = B.PlayerGui:FindFirstChild("TargetGui")
if (TG ~= nil) then
TG:remove()
end
end

script.Parent.ChildAdded:connect(onChildAdded)
script.Parent.ChildRemoved:connect(onChildRemoved)

-------------------

It's an average toolgiver when you sit on a seat, but it's independent so it's in every seat I need it to be but I'd like to turn this into a global. And I do know it'll probably require some brick-within-model maneuvering
Report Abuse
lombardo2 is not online. lombardo2
Joined: 30 Nov 2008
Total Posts: 1604
13 Oct 2013 09:09 AM
What do yo mean by global?

If you are referring to global variables, just no... local variables are faster than global variables.
Report Abuse
Zecrit is not online. Zecrit
Joined: 24 Jan 2013
Total Posts: 2618
13 Oct 2013 09:11 AM
Global functions.
Report Abuse
mic144 is not online. mic144
Joined: 14 Oct 2009
Total Posts: 1598
13 Oct 2013 09:16 AM
_G["TestFunction"] = function()
code
code
code
end

to call:

_G.TestFunction()
Report Abuse
lombardo2 is not online. lombardo2
Joined: 30 Nov 2008
Total Posts: 1604
13 Oct 2013 09:27 AM
That would not reduce lag, just decrease file size. It may even increase the lag because Indexing.
Report Abuse
mic144 is not online. mic144
Joined: 14 Oct 2009
Total Posts: 1598
13 Oct 2013 09:33 AM
Global functions aren't as efficient as people think. They are just useful in some ways.
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