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: Would having a lot of .Changed events cause lag?

Previous Thread :: Next Thread 
Scriptural is not online. Scriptural
Joined: 06 Sep 2013
Total Posts: 2979
02 Feb 2014 02:59 PM
I am making a game that needs a lobby, and so for now its square box (I'm going to work on the scripts first before making the lobby look good) and I'm using this to keep the lobby from being removed (Like if someone was hacking or something I guess)

local BackupLobby = Workspace.Lobby:Clone()
function FixLobby()
NewLobby = Backup:Clone()
Workspace.Lobby:Destroy()
NewLobby.Parent = Workspace
return Workspace.Lobby.DescendantRemoving:connect(FixLobby)
end
Workspace.Lobby.DescendantRemoving:connect(FixLobby)

But what I want to do is put a .Changed event on every object in the lobby so if it gets edited in any way, it fixes itself. Right now its a box, so there aren't a lot of parts, but when I add more parts would it cause a lot of lag to have a .Changed event on each one?
Report Abuse
BEART12 is not online. BEART12
Joined: 22 Oct 2008
Total Posts: 3190
02 Feb 2014 03:28 PM
Using 100 Changed events would properly be better that 2 while true's in my experience they are lag free.
Report Abuse
Scriptural is not online. Scriptural
Joined: 06 Sep 2013
Total Posts: 2979
02 Feb 2014 03:29 PM
I didn't say anything about while loops, but okay thanks
Report Abuse
Scriptural is not online. Scriptural
Joined: 06 Sep 2013
Total Posts: 2979
02 Feb 2014 03:36 PM
This is the script if anyone wants it


function GetDescendants(Object)
local Descendants = {Object}
local function ScanItem(Object)
for _, Instance in pairs (Object:GetChildren()) do
table.insert(Descendants, Instance)
ScanItem(Instance)
end
end
for _, Instance in pairs (Object:GetChildren()) do
table.insert(Descendants, Instance)
ScanItem(Instance)
end
return Descendants
end

local BackupLobby = Workspace.Lobby:Clone()
local LastLobby = Workspace.Lobby
local Events = {}
function ConnectChanges()
for _, Object in pairs (GetDescendants(LastLobby)) do
ChangedEvent = Object.Changed:connect(function()
for _, Event in pairs (Events) do
Event:disconnect()
end
Fix()
end)
table.insert(Events, ChangedEvent)
end
end

function Fix()
LastLobby:Destroy()
BackupLobby:Clone().Parent = Workspace
LastLobby = Workspace.Lobby
Reconnect()
end

ConnectChanges()
Report Abuse
Scriptural is not online. Scriptural
Joined: 06 Sep 2013
Total Posts: 2979
02 Feb 2014 03:39 PM
Oops

function Fix()
LastLobby:Destroy()
BackupLobby:Clone().Parent = Workspace
LastLobby = Workspace.Lobby
ConnectChanges()
end
Report Abuse
duckwit is not online. duckwit
Joined: 08 Aug 2008
Total Posts: 1310
02 Feb 2014 03:46 PM
A while loop is the alternate way of detecting when something has changed. In a non-event-based programming environment you control everything with while loops. Often with many functions branching of a main step/tick function that runs every 1/60th of a second. There are advantages and disadvantages to both, but I think you should go with events for this.
Report Abuse
Scriptural is not online. Scriptural
Joined: 06 Sep 2013
Total Posts: 2979
02 Feb 2014 03:49 PM
I unlocked the lobby and added hopper bins if anyone wants to see it at work :3
Its at my first place
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