|
| 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
|
  |
| 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 |
|
|
|
| 02 Feb 2014 03:29 PM |
| I didn't say anything about while loops, but okay thanks |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 02 Feb 2014 03:39 PM |
Oops
function Fix() LastLobby:Destroy() BackupLobby:Clone().Parent = Workspace LastLobby = Workspace.Lobby ConnectChanges() end |
|
|
| Report Abuse |
|
|
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 |
|
|
|
| 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 |
|
|