Lagging Perlin Noise Problem

Hello!
Recently, I learned about Perlin Noise to make wave systems or even terrain generation. I tried to do some wave system, and it works! But there is a ton of lag!

local resolution = script.Params.res
local amplitude = script.Params.ampl
local frequency = script.Params.freq
local size = 30 --If I put more than 30 here, the game run at 20 fps (this is the number of blocks each side of the grid, so in total there is 30x30 blocks
local speed = script.Params.speed
local Seed = 0

local rValue = resolution.Value
local aValue = amplitude.Value
local fValue = frequency.Value
local sValue = speed.Value

local ts = game:GetService("TweenService")

local function createPart()
	for x = 0, size do
		for z = 0, size do	
			local part = Instance.new("Part", workspace:WaitForChild("PerlinNoisePartContainer"))
			part.Anchored = true
			part.Name = "Part"
			part.CanCollide = false
			part.Size = Vector3.new(1,1,1)
			part.Position = Vector3.new(x,1,z)
		end
		game:GetService("RunService").Heartbeat:Wait()
	end
end

createPart()

while true do	
	for i,v in pairs(workspace.PerlinNoisePartContainer:GetChildren()) do
		local x = v.Position.X
		local z = v.Position.Z
		local y = math.clamp(math.noise(x /rValue * fValue, z / rValue * fValue, Seed), -.5, .5) + .5
		ts:Create(v,TweenInfo.new(sValue, Enum.EasingStyle.Linear), {Position = Vector3.new(x,y*aValue,v.Position.Z), Color = Color3.new(y,y,y)}):Play()
	end
	wait(sValue/100)
	Seed += .1
	
	rValue = resolution.Value
	aValue = amplitude.Value
	fValue = frequency.Value
	sValue = speed.Value
end

I would like to know if there is a way to reduce lag by optimizing the script or the studio.

1 Like