Two, identical functions, not giving same output

Trying to: create waves using editable meshes

Problem: z axis function does not work - cannot figure out why

Notes:
Code block 2 is where the issues are at.

Code that places things down:

local size = Vector2.new(0,5)

local template = game.ReplicatedStorage.template.plane

for u = -size.X/2, size.X/2 do
	for v = -size.Y/2, size.Y/2 do
		
		local clone = template:Clone()
		clone.Parent = game.Workspace.waves.storage
		clone.Position = Vector3.new(u,0,v)
		clone.Script.Enabled = true
	end
end

local start = os.clock()
while true do
	game.ReplicatedStorage.template.Event:Fire(start)
	task.wait(1)
end

Code that makes waves wavy:

local mesh = Instance.new("EditableMesh", script.Parent)

-- Mesh
local dist = 0.5
local tile_count = 0

local function createTile(x,y,z)
	
	local list = {}	
	
	local BL = mesh:AddVertex(Vector3.new(-dist,0,-dist)+Vector3.new(x,y,z)) -- BL
	
	local BR = mesh:AddVertex(Vector3.new(dist,0,-dist)+Vector3.new(x,y,z)) -- BR
	
	local FR = mesh:AddVertex(Vector3.new(dist,0,dist)+Vector3.new(x,y,z)) -- FR
	
	local FL = mesh:AddVertex(Vector3.new(-dist,0,dist)+Vector3.new(x,y,z)) -- FL
	
	local MID = mesh:AddVertex(Vector3.new(0,0,0)+Vector3.new(x,y,z)) -- MID
	
	table.insert(list, BL)
	table.insert(list, BR)
	table.insert(list, FR)
	table.insert(list, FL)
	table.insert(list, MID)
	
	mesh:AddTriangle(BL,BR,MID)
	mesh:AddTriangle(BR,FR,MID)
	mesh:AddTriangle(FR,FL,MID)
	mesh:AddTriangle(FL,BL,MID)
	
	for key, vert in list do
		local pos = mesh:GetPosition(vert)
		mesh:SetUV(vert, Vector2.new(pos.X,pos.Z))
	end

end

for x=-tile_count/2, tile_count/2 do
	
	for z=-tile_count/2, tile_count/2 do
		
		local x = dist*2*x
		local y = 0
		local z = dist*2*z
		
		createTile(x,y,z)
	end
end

local start_time = 0

game.ReplicatedStorage.template.Event.Event:Connect(function(delta)
	--start_time = delta
end)

local function doStuff(input_x, input_z, f, d, a, delta)

	--local f1 = math.sin(math.cos(f * pos.X - delta)) * d.X
	--local f2 = math.cos(math.sin(f * pos.X - delta)) * d.X
	--local x = a * math.sin(math.cos(f * pos.X - delta)) * f1 * f2 * d.X

	--local f3 = math.sin(math.cos(f * pos.Y - delta)) * d.Y
	--local f4 = math.cos(math.sin(f * pos.Y - delta)) * d.Y
	--local z = a * math.sin(math.cos(f * pos.Y - delta)) * f3 * f4 * d.Y
	
	local x1 = a * math.sin(math.cos(f * input_x - delta))
	local z1 = a * math.sin(math.cos(f * input_z - delta))
	
	return Vector3.new(x1,x1+z1,z1)
end

while true do
	
	local f = game.ReplicatedStorage.template.Frequency.Value
	local d = game.ReplicatedStorage.template.Direction.Value
	local a = game.ReplicatedStorage.template.Amplitude.Value
	local s = game.ReplicatedStorage.template.Speed.Value

	local delta = os.clock() - start_time
	
	for key, vert in mesh:GetVertices() do
		
		local pos = script.Parent.Position
		
		local rel_pos = mesh:GetPosition(vert)
		
		local world_pos = Vector3.new(
			rel_pos.X + pos.X, 
			rel_pos.Y + pos.Y, 
			rel_pos.Z + pos.Z
		)
		
		local temp = doStuff(world_pos.X, world_pos.Z, f, d, a, delta)
		
		mesh:SetPosition(vert, Vector3.new(rel_pos.X, temp.Y, rel_pos.Z))
		
	end
	
	task.wait()
end