|
| 30 Oct 2016 09:43 PM |
This code can get laggy so I had to put waits(). What It does is scans all the torso to see if they've entered a certain "zone". Is there a more efficient way to do this for less lag?
local Captured = ""
while wait(1) do local function ConfirmPosition(Zone, Torso) local tp = Torso.Position local ap = Zone.Position local as = Zone.Size local ax = (as.X + 1)/2 local ay = (as.Z + 1)/2 local ax1 = ap.X - ax local ax2 = ap.X + ax local ay1 = ap.Z - ay local ay2 = ap.Z + ay if tp.X > ax1 and tp.X < ax2 and tp.Z > ay1 and tp.Z < ay2 then return true else return false end end local function ReturnPosition(Torso) if ConfirmPosition(script.Parent, Torso) then return true else return false end end local AllTorsos = {} for _, Object in pairs(workspace:GetChildren()) do if Object:IsA("Model") and Object:FindFirstChild("Torso") then local Torso = Object:FindFirstChild("Torso") local Player = game.Players:GetPlayerFromCharacter(Torso.Parent) if ReturnPosition(Torso) and Player then table.insert(AllTorsos, Player.Name) end end wait(0.1) end if #AllTorsos == 1 then print("CAPTURED BY "..Captured) elseif #AllTorsos > 1 then print(#AllTorsos.." PLAYERS FIGHTING") end end
|
|
|
| Report Abuse |
|
|
| |
|
chimmihc
|
  |
| Joined: 01 Sep 2014 |
| Total Posts: 17143 |
|
|
| 30 Oct 2016 10:21 PM |
The first thing you should do is stop creating so many functions. That creates two functions and a table EVERY TIME IT LOOPS.
|
|
|
| Report Abuse |
|
|
Dr_Doge
|
  |
| Joined: 07 Dec 2011 |
| Total Posts: 645 |
|
|
| 30 Oct 2016 10:24 PM |
| Mind if I use this code for stuff? |
|
|
| Report Abuse |
|
|
|
| 30 Oct 2016 10:31 PM |
@chimmihc all I need at the moment is for this code to run much more smoother, that's all. I have an idea that will fix the issue you are concerned about me running into.
|
|
|
| Report Abuse |
|
|
Salinas23
|
  |
| Joined: 28 Dec 2008 |
| Total Posts: 37141 |
|
|
| 30 Oct 2016 10:54 PM |
place the functions outside the loop
make it loop every 2 seconds, not 1
I have a spider on my back. |
|
|
| Report Abuse |
|
|
| |
|
|
| 31 Oct 2016 12:40 PM |
| You've been answered already: maybe increase the delay, definitely define the functions outside the loop. |
|
|
| Report Abuse |
|
|
|
| 31 Oct 2016 03:17 PM |
Don't make a list of everything in the Workplace.
I have seen a ClosestPlayer routine (not NearestTorso) on this Forum and in some Zombies which only checks the Player's Torsos.
Look in the Library.
|
|
|
| Report Abuse |
|
|