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:

Shrinker = script.Parent
StepSize = 0.5 --In Studs
Lenght = 30 --In seconds
ColorTransmissionTime = 5
FinalTransparency = 0.2
Size = Shrinker.Part.Size.X

for i, v in pairs(Shrinker:GetChildren()) do
	if v:IsA("Part") then
		spawn(function()--Spawn function
			
			v.Touched:connect(function(Hit)
				if Hit:IsA("Part") then
				if Hit.Parent:FindFirstChild("Humanoid") then
					
					Hit.Parent.Humanoid.Health = 0--Kill

					local Explosion = Instance.new("Explosion")--Effect
					Explosion.Position = Hit.Position
					Explosion.DestroyJointRadiusPercent = 0
					Explosion.Parent = game.Workspace
				end
				end
			end)
			
			v.Transparency = 1

			for i = 1,100-FinalTransparency*100 do
				v.Transparency = v.Transparency - 0.01
				wait(ColorTransmissionTime/(100-FinalTransparency*100))
			end

			for i = 1, Size/StepSize/2 do--Change Size and Position
				local targetCFrame = v.CFrame + (v.CFrame.lookVector * StepSize)
                v.Size = (v.Size - Vector3.new(StepSize*2,StepSize*2,StepSize*2))
                v.CFrame = targetCFrame
                wait (Lenght/(Size/StepSize/2))
			end
		end)
	end
end

Thanks for trying to help! ;)

3 comments

0

Try putting a wait

0

They are there already.

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.