Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » How do I make my project less laggy?
- CoolBoy4286
-
100+ posts
How do I make my project less laggy?
I was trying to use this script in my project https://scratch.mit.edu/projects/568410170/ , it work too but makes the project lag a lot, please help me by suggesting a script that does the same thing but isn't this laggy.
The script I used:
Also the set variables block is run without screen refresh.
The script I used:
when green flag clicked
forever
set size to variable size
go to [ mouse pointer]
set variables
define set variables
forever
set variable mass to density*volume
set variable gravitational constant to 9.8
set variable gravity to gravitational constant*mass/size
set variable density to mass/volume
set variable volume to size
end
Also the set variables block is run without screen refresh.
Last edited by CoolBoy4286 (Sept. 30, 2021 16:45:34)
- gdxfor
-
100+ posts
How do I make my project less laggy?
You don't need the second forever loop as the set variable is going to get called forever anyways
- aidynmartinez2
-
98 posts
How do I make my project less laggy?
it does not seemly laggy but maybe it's cause i got a good computer, anyway pout in the instructions to go here: https://turbowarp.org/568410170 (less laggy)
- CoolBoy4286
-
100+ posts
How do I make my project less laggy?
https://turbowarp.org/568410170 (less laggy)Maybe you do, but I don't have the scripts in the game yet because it's too laggy, without those scripts, the game runs fine. it does not seemly laggy but maybe it's cause i got a good computer, anyway pout in the instructions to go here:
- CoolBoy4286
-
100+ posts
How do I make my project less laggy?
Thanks for trying to help, but that does not decrease lag (maybe it does but I can't notice it). You don't need the second forever loop as the set variable is going to get called forever anyways
- DavidJag
-
73 posts
How do I make my project less laggy?
I notice you're detecting the S key in a loop. This will create a clone every frame (1/30 of a second) for as long as you hold down the S key. Potentially you may have lots of clones all at the same position which you won't be able to see but could cause lag.
Also, you could join both of your forever loops under your green flags into a single loop
Also, you could join both of your forever loops under your green flags into a single loop
- CoolBoy4286
-
100+ posts
How do I make my project less laggy?
Yes ik but idk how to fix it. I notice you're detecting the S key in a loop. This will create a clone every frame (1/30 of a second) for as long as you hold down the S key. Potentially you may have lots of clones all at the same position which you won't be able to see but could cause lag.
Also, you could join both of your forever loops under your green flags into a single loop
If I never let the project reach clone limit does that reduce lag? (the project will always be at 299 clones)
- PSIstudios
-
500+ posts
How do I make my project less laggy?
How many clones are there when you take out the code?
- DavidJag
-
73 posts
How do I make my project less laggy?
Remove your key code and add this script to only add one clone at a time
when [s v] key pressed
create clone of [myself v]
wait until <not <key [s v] pressed?>>
Last edited by DavidJag (Oct. 7, 2021 18:50:42)
- CoolBoy4286
-
100+ posts
How do I make my project less laggy?
I modified your code so that it deletes all the clones after it reaches the clone limit, to keep track of that I used the clone count variable, but for some weird reason the variable goes all the way up to 301 instead of 300, can you explain to why? Remove your key code and add this script to only add one clone at a timewhen [s v] key pressed
create clone of [myself v]
wait until <not <key [s v] pressed?>>
I used this script:
when [ S v] key pressedAnd my project is still very laggy even after doing everything everyone here told me to
change [ Clone count v] by (1 )
create clone of [ myself v]
wait until <not <key [ S v] pressed?>>
change [ Clone count v] by (-1 )
delete this clone

And now I'm facing 2 more problems, the variables go large numbers and I can't lower them the spawner doesn't go to the mouse pointer but to a random place and for some reason pressing the Skey starts the game (probably because i'm using a hat block to sense it.
Last edited by CoolBoy4286 (Oct. 8, 2021 15:15:55)
- CoolBoy4286
-
100+ posts
How do I make my project less laggy?
After a lot of time my project finally started working, thank you to everyone who helped me
and I also got an awesome unintended feature, the clones now have spawnpoints which they go to at the start of the game and after hitting the player.

Last edited by CoolBoy4286 (Oct. 8, 2021 15:04:15)
- dyingneko
-
48 posts
How do I make my project less laggy?
https://scratch.mit.edu/projects/568410170/ , it work too but makes the project lag a lot, please help me by suggesting a script that does the same thing but isn't this laggy.Run without screen refresh can cause a lot of lag on older, less capable machines and the script isn’t much so I would recommend disabling it. I was trying to use this script in my project
The script I used:when green flag clicked
forever
set size to variable size
go to [ mouse pointer]
set variables
define set variables
forever
set variable mass to density*volume
set variable gravitational constant to 9.8
set variable gravity to gravitational constant*mass/size
set variable density to mass/volume
set variable volume to size
end
Also the set variables block is run without screen refresh.
Another reason it might be performing badly could be due to the math it is running every second. The
(() * ())operator lags a lot for my device. Removing the forever loop from the custom block will help solve is by a tad bit. I’ll analyse more and get back to you

- CoolBoy4286
-
100+ posts
How do I make my project less laggy?
Thanks, but the topic is resolved and I will close it later.https://scratch.mit.edu/projects/568410170/ , it work too but makes the project lag a lot, please help me by suggesting a script that does the same thing but isn't this laggy.Run without screen refresh can cause a lot of lag on older, less capable machines and the script isn’t much so I would recommend disabling it. I was trying to use this script in my project
The script I used:when green flag clicked
forever
set size to variable size
go to [ mouse pointer]
set variables
define set variables
forever
set variable mass to density*volume
set variable gravitational constant to 9.8
set variable gravity to gravitational constant*mass/size
set variable density to mass/volume
set variable volume to size
end
Also the set variables block is run without screen refresh.
Another reason it might be performing badly could be due to the math it is running every second. The(() * ())operator lags a lot for my device. Removing the forever loop from the custom block will help solve is by a tad bit. I’ll analyse more and get back to you
- dyingneko
-
48 posts
How do I make my project less laggy?
Thanks, but the topic is resolved and I will close it later.https://scratch.mit.edu/projects/568410170/ , it work too but makes the project lag a lot, please help me by suggesting a script that does the same thing but isn't this laggy.Run without screen refresh can cause a lot of lag on older, less capable machines and the script isn’t much so I would recommend disabling it. I was trying to use this script in my project
The script I used:when green flag clicked
forever
set size to variable size
go to [ mouse pointer]
set variables
define set variables
forever
set variable mass to density*volume
set variable gravitational constant to 9.8
set variable gravity to gravitational constant*mass/size
set variable density to mass/volume
set variable volume to size
end
Also the set variables block is run without screen refresh.
Another reason it might be performing badly could be due to the math it is running every second. The(() * ())operator lags a lot for my device. Removing the forever loop from the custom block will help solve is by a tad bit. I’ll analyse more and get back to you
I wish you a smooth sail in your project’s journey!

- CoolBoy4286
-
100+ posts
How do I make my project less laggy?
Thank youThanks, but the topic is resolved and I will close it later.https://scratch.mit.edu/projects/568410170/ , it work too but makes the project lag a lot, please help me by suggesting a script that does the same thing but isn't this laggy.Run without screen refresh can cause a lot of lag on older, less capable machines and the script isn’t much so I would recommend disabling it. I was trying to use this script in my project
The script I used:when green flag clicked
forever
set size to variable size
go to [ mouse pointer]
set variables
define set variables
forever
set variable mass to density*volume
set variable gravitational constant to 9.8
set variable gravity to gravitational constant*mass/size
set variable density to mass/volume
set variable volume to size
end
Also the set variables block is run without screen refresh.
Another reason it might be performing badly could be due to the math it is running every second. The(() * ())operator lags a lot for my device. Removing the forever loop from the custom block will help solve is by a tad bit. I’ll analyse more and get back to you
I wish you a smooth sail in your project’s journey!

- Discussion Forums
- » Help with Scripts
-
» How do I make my project less laggy?