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 » Scripters
Home Search
 

Re: Effecienct code

Previous Thread :: Next Thread 
peoplemove12 is not online. peoplemove12
Joined: 11 Feb 2010
Total Posts: 1442
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
peoplemove12 is not online. peoplemove12
Joined: 11 Feb 2010
Total Posts: 1442
30 Oct 2016 10:20 PM
b1


Report Abuse
chimmihc is not online. 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 is not online. 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
peoplemove12 is not online. peoplemove12
Joined: 11 Feb 2010
Total Posts: 1442
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 is not online. 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
peoplemove12 is not online. peoplemove12
Joined: 11 Feb 2010
Total Posts: 1442
31 Oct 2016 12:24 PM
b2


Report Abuse
pinballboy7 is not online. pinballboy7
Joined: 12 Mar 2009
Total Posts: 1485
31 Oct 2016 12:40 PM
You've been answered already: maybe increase the delay, definitely define the functions outside the loop.
Report Abuse
BJCarpenter is online. BJCarpenter
Joined: 04 Nov 2008
Total Posts: 4416
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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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