Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is this script causing too much lag?

Asked by 9 years ago

I've made this script, it is scaling a huge box at size about 500x500x500 out of 6 Parts, which kill you on touch. Even though the script works properly, it causes a huge amount of lag. When I checked the Script Performance, it was taking up about 80. Here it is:

01Shrinker = script.Parent
02StepSize = 0.5 --In Studs
03Lenght = 30 --In seconds
04ColorTransmissionTime = 5
05FinalTransparency = 0.2
06Size = Shrinker.Part.Size.X
07 
08for i, v in pairs(Shrinker:GetChildren()) do
09    if v:IsA("Part") then
10        spawn(function()--Spawn function
11 
12            v.Touched:connect(function(Hit)
13                if Hit:IsA("Part") then
14                if Hit.Parent:FindFirstChild("Humanoid") then
15 
View all 41 lines...

Thanks for trying to help! ;)

0
Try putting a wait LittleBigDeveloper 245 — 9y
0
They are there already. Dolphinous 36 — 9y
0
you have 6 blocks all having an touched event but also 2 loops so when adding them all up thats a lot of loops to do and threads, try and share the math logic e.g. do it once then set the values? but i dont know how you want to use this script. User#5423 17 — 9y

Answer this question