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: Can't figure out why this part of the script lags the game.

Previous Thread :: Next Thread 
Powerhalo is not online. Powerhalo
Joined: 16 Jun 2010
Total Posts: 1504
23 Jul 2014 09:00 PM
So as soon as this part of the script runs, the game lags so much. I would like to know why and if there's a fix. I scripted most of it and I can't figure out what's causing all the lag.


players = game.Players:GetPlayers()
knifer = players[math.random(1,#players)]
knifer.Role.Value = "knifer"
kniferknife.Parent = knifer.Backpack
gunner = players[math.random(1,#players)]
gunner.Role.Value = "gunner"
gunnergun.Parent = gunner.Backpack
info.started.Value = true
TeleportLocation = Vector3.new(0, 0, 0)
Position = Vector3.new(game.Workspace.Map.Spawn1.Position)
PlayersInGame = game.Players:GetChildren()
for i = 1, #PlayersInGame do
PlayersInGame[i].Character:MoveTo(TeleportLocation + Position)
wait(1/30)
end
for lol=180,0, -1 do
wait(1)
info.timer.Value = lol
end
knifer.Role.Value = ""
gunner.Role.Value = ""
knifer.Backpack.Knife:remove()
gunner.Backpack.Knife:remove()
info.started.Value = false
end
until nil

Thanks alot
Report Abuse
Powerhalo is not online. Powerhalo
Joined: 16 Jun 2010
Total Posts: 1504
23 Jul 2014 09:00 PM
PS: It's only part of the script so the script alone doesn't work, I'm just looking for ways to optimize the script.
Report Abuse
Powerhalo is not online. Powerhalo
Joined: 16 Jun 2010
Total Posts: 1504
23 Jul 2014 09:26 PM
Bump.
Report Abuse
blockoo is not online. blockoo
Joined: 08 Nov 2007
Total Posts: 17202
23 Jul 2014 09:28 PM
What's the point of the "until nil" line at the bottom if you don't have a "repeat"? Try taking that out.
Report Abuse
smiley599 is not online. smiley599
Joined: 23 Jan 2010
Total Posts: 21869
23 Jul 2014 09:29 PM
dont do (repeat) until nil

use a while loop
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
23 Jul 2014 09:30 PM
@smiley599: Real advice please. repeat-until is different from while-do and has a different purpose.
Report Abuse
smiley599 is not online. smiley599
Joined: 23 Jan 2010
Total Posts: 21869
23 Jul 2014 09:32 PM
...

not in this case

He's doing repeat until nil which is the same as while true do

WHENS NIL NOT GOING TO BE NIL
Report Abuse
blockoo is not online. blockoo
Joined: 08 Nov 2007
Total Posts: 17202
23 Jul 2014 09:33 PM
Except that he's not even using a repeat because the word "repeat" isn't anywhere in that script.
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
23 Jul 2014 09:38 PM
@smiley599: So why does it matter?

If you are going to say "No do not use A use B which does exactly the same thing with no less work" then give a reason.
Report Abuse
smiley599 is not online. smiley599
Joined: 23 Jan 2010
Total Posts: 21869
23 Jul 2014 09:39 PM
I think it looks nicer with an end rather than until nil.

yeh im nuts
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
23 Jul 2014 09:40 PM
That is not a valid reason.
Report Abuse
smiley599 is not online. smiley599
Joined: 23 Jan 2010
Total Posts: 21869
23 Jul 2014 09:40 PM
omg why you being so mean all of a sudden
Report Abuse
Powerhalo is not online. Powerhalo
Joined: 16 Jun 2010
Total Posts: 1504
24 Jul 2014 11:53 AM
I removed the repeat and until nil. The game still lags alot at that part of the script :/
Report Abuse
Powerhalo is not online. Powerhalo
Joined: 16 Jun 2010
Total Posts: 1504
24 Jul 2014 11:58 AM
Okay, after eliminating parts of the script, I concluded that the teleport section of the script caused the lag. Any fixes?
Report Abuse
Powerhalo is not online. Powerhalo
Joined: 16 Jun 2010
Total Posts: 1504
24 Jul 2014 12:09 PM
This part makes the lag:

TeleportLocation = Vector3.new(0, 0, 0)
Position = Vector3.new(game.Workspace.Map.Spawn1.Position)
PlayersInGame = game.Players:GetChildren()
for i = 1, #PlayersInGame do
PlayersInGame[i].Character:MoveTo(TeleportLocation + Position)
wait(1/30)
Report Abuse
Powerhalo is not online. Powerhalo
Joined: 16 Jun 2010
Total Posts: 1504
24 Jul 2014 12:23 PM
Nevermind, the teleport isn't what's causing the lag O_o
Report Abuse
blockoo is not online. blockoo
Joined: 08 Nov 2007
Total Posts: 17202
24 Jul 2014 03:04 PM
How long is the whole script?
Report Abuse
maxomega3 is not online. maxomega3
Joined: 11 Jun 2010
Total Posts: 10668
24 Jul 2014 03:09 PM
It's inefficient, so imma fix it anyway

TeleportLocation = Vector3.new(0, 0, 0)
Position = Vector3.new(game.Workspace.Map.Spawn1.Position)
PlayersInGame = game.Players:GetChildren()
for i = 1, #PlayersInGame do
PlayersInGame[i].Character:MoveTo(TeleportLocation + Position)
wait(1/30)

becomes

PlayersInGame = game.Players:GetPlayers ()
for i,v in pairs (PlayersInGame) do
PlayersInGame[i].Character:MoveTo (Workspace.Map.Spawn1.Position)
wait ()
end

Report Abuse
Powerhalo is not online. Powerhalo
Joined: 16 Jun 2010
Total Posts: 1504
24 Jul 2014 03:28 PM
Thanks guys. I found out what lagged the game and fixed it :D
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